简体   繁体   English

UITableViewController数据源来自coredata

[英]UITableViewController data source from coredata

I have found two ways of populating UITableView with data from coredata. 我发现了两种用coredata中的数据填充UITableView方法。 One way is to use NSFetchedResultsController and implement the delegates for update controller:didChangeSection . 一种方法是使用NSFetchedResultsController并实现用于update controller:didChangeSection的委托。 Other way is to copy data from coredata to local array of Managed objects. 另一种方法是将数据从coredata复制到托管对象的本地数组。 Handle the updates on local array and saves the changes to managedcontex. 处理本地阵列上的更新,并将更改保存到managedcontex。 Both could be found on developer.apple.com. 两者都可以在developer.apple.com上找到。

I would like to hear pros and cons for each metod? 我想听听每种方法的利弊吗?

Thanks. 谢谢。

It is better to use NSFetchedResults controller, because your current view controller may not be the only one changing the data. 最好使用NSFetchedResults控制器,因为当前的视图控制器可能不是唯一更改数据的控制器。 It may happen in the background, or through some other view controller (for example, if you have a split view controller, you may be changing data related to a record in the master view controller, in the detail view controller). 它可能在后台或通过其他视图控制器发生(例如,如果您有拆分视图控制器,则可能在细节视图控制器的主视图控制器中更改与记录相关的数据)。 In those cases, you want your table to automatically reflect the changes. 在这种情况下,您希望表自动反映更改。 In extremely simple cases, where you are the only view controller in town, it may be easier the other way, but do it the right way and you will be happy. 在非常简单的情况下,如果您是该镇上唯一的视图控制器,则反之可能会更容易,但是以正确的方式进行操作,您会感到很高兴。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM