.xib 具有多个 UITableView 或 UIPopoverController 中的多个列表
所以我需要创建一个从 UIPopoverController 呈现的过滤器。要过滤的不同列表转到数据管理器(模型)类并查询 sqlite 数据库。我概念化的问题是如何以最大的可重用性对多个 UIPopoverController 执行此操作。我的意思是,如果我有两个过滤器,一个用于水果,另一个用于蔬菜。每个都需要在弹出窗口中呈现。
我所做的是,我有一个具有通用数组的 UITableView。在呈现弹出窗口的类中,根据按下的过滤器,我会呈现带有 UITableView 的弹出窗口以及相应的水果和蔬菜列表。
对我来说最棘手的部分是复选标记的问题。由于我的列表由“全部”以及“Apple”或“Orange”等每个条目组成,因此当用户选择“全部”时,看不到其他复选标记。如果用户选择“苹果”,则所有内容都将被取消选择,并且“苹果”将被选中并带有复选标记。如果再次选择 apple,则取消选择 apple,并重新选择 All。我处理这个问题的方法是,在 didSelectrowForIndexPath 中,我查询模型类,获取每个键的 YES/NO 值的 NSDictionary,然后设置它。这也会处理弹出窗口关闭然后再次呈现的情况,然后复选标记都处于模型已更新后所处的最后状态。
所以我的两个问题是
(1)如果这个实现是“ok”,那么我如何为每个 UITableView 提供一个单独的列表?似乎由于 UITableView 管理一个列表,我需要创建多个 UITableView,每个过滤器一个,因此对数据管理器的那些特定调用(例如“全部”)不会弄乱其他过滤器
(2)有更好的方法吗?我愿意接受建议!谢谢!
So I need to create a filter that is presented from a UIPopoverController. The different lists to filter on go to the data manager (model) class and query the sqlite database. The problem I am having conceptualizing is how to do this for multiple UIPopoverControllers with the most reusability. What I mean by that is, if I have two filters, one for say fruits, and another for say vegetables. Each one needs to be presented in a popover.
What I have done is, I have a UITableView that has a generic array. In the class that presents the popover, depending on what filter was pressed, I present the popover with the UITableView and the corresponding fruit and vegetable list.
The tricky part for me is, the problems with the checkmarks. Since my list consists of "All", plus each entry like "Apple" or "Orange", when the user selects All, no other checkmarks are visible. If the user selects apple, then all is deselected, and apple is selected with a checkmark. If apple is selected again, then apple is deselcted, and All is reselected. The way I handle this is, in didSelectrowForIndexPath, I query the model class, get my NSDictionary of YES/NO values for each key, and set it. This also takes care of when the popover is closed, and then presented again, then the checkmarks are all there in the last state they were in since the model was already updated.
So my two questions are
(1) if this implementation is 'ok,' then how would I have a separate list for each UITableView? It seems like since the UITableView manages one list, I would need to create multiple UITableViews, one for each filter, so those specific calls to the data manager, like "All", don't mess up the other filters
(2) is there a better way to do this? I'm open to suggestions! Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要重新考虑用户界面。可能没有必要将“全部”作为选项,甚至最好将其省略。
我检查了此类过滤器在其他应用程序中的工作原理,发现“全部”通常不是一个选项。当表格第一次出现时,默认显示所有水果。当选择一项(例如“Apple”)时,仅显示苹果。当取消选择“Apple”时,所有结果将再次显示。
当然,这与逻辑相反。从逻辑上讲,如果未选择任何内容,则不应显示任何内容。然而,我发现,当您使用这样一个不带“全部”选项的过滤器时,您不会意识到逻辑上的不一致,而且它在某种程度上工作得非常顺利,正如您所期望的那样。另一方面,当用户选择完全不同的条目时,自动选中和取消选中“全部”对于用户体验来说可能显得更麻烦。
我就是用这种方式实现了一个过滤器。在我看来,即使不太符合逻辑,它也更加用户友好。
至于实现,我只是将 UITableViewController 子类化并为过滤器条目设置一个数组属性。然后我将我的子类重新用于不同的过滤器。
You may want to reconsider the user interface. It may not be necessary to have "All" as an option, and it may even be preferable to leave it out.
I've checked out how such filters work in other apps, and I've found that "All" is often not an option. When the table first appears, all fruits, say, are shown by default. When one entry, say "Apple", is selected, only apples are shown. When "Apple" is deselected, all results are shown once again.
This, of course, is the inverse of what is logical. Logically, if nothing is selected, nothing should be shown. However, I've found that when you're using such a filter without the "All" option, you don't realize the logical inconsistency and it somehow works very smoothly, as you would expect it to. On the other hand, it may appear more cumbersome for the user experience to have "All" being checked and unchecked automatically when the user is selecting an entirely different entry.
I've implemented a filter in just this way. In my opinion, it's more user friendly even if it's less logical.
As to the implementation, I just subclassed UITableViewController and set an array property for the filter entries. Then I re-use my subclass for different filters.