简体   繁体   English

构建应用以在单个UITableView中显示两个列表的最佳方法是什么(在数据集之间切换)

[英]What's the best way of building an app to display two lists in a single UITableView (switching between datasets)

I'm relatively new to iOS development and am just wanting a few pointers as to what will be the best way to go about doing this. 对于iOS开发,我是相对较新的人,只想提供一些有关实现此目标的最佳方法的建议。 I am building an app with a tab bar and one of those tabs will be a table view at the top of which is a segmented control with two buttons allowing you to swap between datasets. 我正在构建一个带有标签栏的应用程序,这些标签之一将是一个表格视图,其顶部是带有两个按钮的分段控件,允许您在数据集之间交换。

The first question I have is: 我的第一个问题是:

The data is relatively simple but there are about 6000 records would it be best to use a simple NSDictionary as the data source or should I look into using Core Data. 数据相对简单,但是大约有6000条记录,最好是使用简单的NSDictionary作为数据源,或者我应该考虑使用Core Data。 Users of the app will simply be able to select a record to add it to a favourites list, or deselect it. 应用程序的用户只需选择一条记录即可将其添加到收藏夹列表中,或取消选择它。

Secondly: 其次:

Should I use two different view controllers and swap them in and out depending on which option is selected or should I use a single view controller and swap the data in that class to populate the table. 我应该使用两个不同的视图控制器并根据选择的选项交换它们进出,还是应该使用单个视图控制器并交换该类中的数据来填充表。

I'm a registered Apple Dev so I have access to their examples but often can find them difficult to follow, any pointers to resources/tutorials would be VERY appreciated. 我是Apple Dev的注册会员,因此可以访问它们的示例,但经常会发现它们很难理解,因此非常感谢所有指向资源/教程的指针。

First off, for anything nontrivial always consider Core Data - in your case especially so. 首先,对于任何无关紧要的事情,请始终考虑核心数据-在您的情况下尤其如此。 A 6000-object dictionary can easily get unwieldy to manage. 包含6000个对象的字典很容易变得难以管理。

As for the view controllers, I believe the canonical thing to do is to use a single table view controller (since you remain on a single UITabBarController tab), but change out its data source, or just change the data returned from that source. 对于视图控制器,我认为规范的工作是使用单个表视图控制器(因为您仍留在单个UITabBarController选项卡上),但更改其数据源,或仅更改从该源返回的数据。

If you need it to look reasonably smooth, you can play with the built-in UITableView animation methods - I believe the AP application changed out its news stories by animating out all the old ones and animating in all the new ones within a single table view, so the effect was of a complete dataset change but without the extra view controller. 如果您需要使其看上去相当平滑,则可以使用内置的UITableView动画方法-我相信AP应用程序通过在单个表格视图中对所有旧的动画进行动画处理并对所有新的动画进行动画处理来改变其新闻报道。 ,因此效果是完整的数据集更改,但没有额外的视图控制器。

Generally I've found the Apple examples and tutorials to be the best available, but there's no substitute for just building apps and playing around with the technologies yourself - if you don't understand an example, try to reimplement it yourself and see what's giving you trouble. 总的来说,我发现Apple的示例和教程是最合适的,但是没有什么可以替代自己构建应用程序并亲自使用这些技术的-如果您不了解示例,请尝试自己重新实现,然后看看有什么用你麻烦 If you're truly stuck on something, come back and ask another question! 如果您确实卡在某个东西上,请回来再问一个问题!

First question: 第一个问题:

If your dataset is fairly simple, I would recommend sticking with an array of dictionaries; 如果您的数据集非常简单,我建议您坚持使用一系列词典; or, if order is well-defined, and each row has a meaningful unique key, simply use a dictionary. 或者,如果顺序定义明确,并且每一行都有有意义的唯一键,则只需使用字典。

There's a complexity tradeoff involved in using a large framework like Core Data, and until you have—for instance—relationships expressed in your object model, I don't think the tradeoff is worth taking. 使用像Core Data这样的大型框架时,需要进行复杂的权衡,并且直到您在对象模型中表达了关系之前,我才认为这种权衡是不值得的。

That said, there are performance issues to take into account when making these kinds of decisions. 就是说,在做出此类决策时要考虑性能问题。 You have 6,000 records, but is each just a key and a value? 您有6,000条记录,但是每条记录都是键和值吗? That wouldn't be such a big deal. 没什么大不了的。 But if you have a number of columns, and sorting is an issue, Core Data's SQLite backend would help you out a great deal. 但是,如果您有许多列,并且排序是一个问题,那么Core Data的SQLite后端将为您提供很多帮助。

If the array or dictionary is filled with standard Foundation data types, you'd get serialization for free, since all of them implement NSCoding. 如果数组或字典中填充了标准的Foundation数据类型,则您将免费获得序列化 ,因为它们都实现了NSCoding。

Second question: 第二个问题:

Read through Apple's article on the model-view-controller design paradigm . 通读Apple 关于model-view-controller设计范例的文章 The thing to note about what you're trying to do here is that since you're only looking to vary your data, only your model should be changing. 关于您要在此处执行的操作要注意的事情是,由于您只想更改数据,因此只应更改模型。

UITableView is designed to make that easy. UITableView旨在UITableView这一过程。 It's a view, so it doesn't store its data, but it has a dataSource property which it queries to display information. 这是一个视图,因此它不存储其数据,但是它具有dataSource属性,可以查询该属性以显示信息。 So when your user switches datasets, simply switch your table view's data source. 因此,当用户切换数据集时,只需切换表视图的数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在UITableview中显示缩略图列表的最佳方法是什么 - What is the best way to display thumbnail list in UITableview 在UINavigationController层次结构中刷新UITableView的最佳方法是什么 - What's the best way to refresh a UITableView within a UINavigationController hierarchy 创建UITableView表单的最佳和最简单的方法是什么? - What's the best and easiest way to create a UITableView form? 根据UITableView中的位置返回不同单元格的最佳方法是什么 - What's the best way to return different cells depending on position in a UITableView iPhone:显示“报告”的最佳方法是什么? - iPhone: what's the best way to display a "report'? 在运行相同应用程序的两个iOS设备之间传输对象的最佳方法是什么? - What is the best way to transfer an object between two iOS devices running the same app? 检测两个iphone / ipod / ipad之间距离的最佳方法是什么? - What is the best way to detecting distance between two iphone/ipod/ipad? 下载多个图像并显示多个UIImageView的最佳方法是什么? - What's the best way to download multiple images and display multiple UIImageView? UITableViewCell里面的UITableView? 什么是最好的设计? - UITableView inside a UITableViewCell? What's the best design? 视图控制器之间通信的最佳方式是什么? - What's the best way to communicate between view controllers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM