controllerDidChangeContent:每次在核心数据中创建 ManagedObject 时调用
我有一个使用 NSFetchedResultsController 从核心数据存储加载数据的表视图,我正在实现controllerDidChangeContent:用新数据(从远程源加载)更新表,但是,一旦我创建,就会调用委托方法controllerDidChangeContent:一个托管对象,据我所知,只有当我在相应的托管对象上下文上发送消息 save: 时才应该调用它。
是否需要设置一个参数来启用此功能?
我正在下载一个 XML,其中包含许多要插入到表视图中的项目,但我遇到了崩溃,因为我正在动态创建托管对象并动态附加信息,其中一些信息需要显示在表视图单元格中。
因此,通过每次创建新的托管对象时调用controllerDidChangeContent:,我创建表视图单元格所需的属性尚未准备好。
任何见解都会很棒。
谢谢。
I have a tableview using NSFetchedResultsController to load data from the Core Data store, I am implementing controllerDidChangeContent: to update the table with new data (loaded from a remote source), however, the delegate method controllerDidChangeContent: is being called as soon as I create a Managed Object, it was my understanding that this should only be called when I message save: on the corresponding Managed Object Context.
Is there a parameter to set to enable this ?
I am downloading an XML with many items to insert into the tableview and I'm getting crashes because I am creating my Managed Objects on the fly and appending information on the fly, some of which are required to be displayed in the Table View Cell.
Therefore by controllerDidChangeContent: being called each time I create a new Managed Object, the properties I require to make the Table View Cell are not yet ready.
Any insight would be great.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法禁用 NSFetchedResultsController 的此行为。为了防止这种情况,您可以创建第二个 NSManagedObjectContext,在那里执行所有插入、更改和删除操作,最后使用
mergeChangesFromContextDidSaveNotification:
合并两个上下文:当您下载 XML 文件时,您也应该在后台执行此操作线程以防止 UI 因用户输入而被阻止。
You can't disable this behavior of the NSFetchedResultsController. To prevent this you can create a second NSManagedObjectContext, do all your inserts, changes and deletes there and finally merge both contexts with the
mergeChangesFromContextDidSaveNotification:
As your are downloading an XML file you also should do this in a background thread to prevent the UI being blocked for user inputs.