是否为Core Data的获取结果控制器实现委托 [英] Implement delegates for Core Data's fetched results controller or not

查看:60
本文介绍了是否为Core Data的获取结果控制器实现委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实现四个委托方法有什么好处:

What advantage is there to implementing the four delegate methods:


  • (void)controllerWillChangeContent:(NSFetchedResultsController *)controller

  • (void)controllerWillChangeContent:(NSFetchedResultsController *)controller

(void)controller:(NSFetchedResultsController *)controller didChangeSection:(id)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type

(void)controller:(NSFetchedResultsController *)controller didChangeSection:(id )sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type

(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath

(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath

(void)controllerDidChangeContent:(NSFetchedResultsController *)controller

(void)controllerDidChangeContent:(NSFetchedResultsController *)controller

而不是实现:


  • (void)controllerDidChangeContent:(NSFetchedResultsController *)controller

任何帮助表示赞赏//:)

Any help appreciated // :)

推荐答案

在使用时FetchedResultsContr借助表视图,您可以实现这四个委托方法以响应对获取的结果所做的每个更改,并在表中发生更改时对其进行动画处理。但是,作为NSFetchedResultsControllerDelegate 文档状态:

When you're using the FetchedResultsController with a table view, you can implement those four delegate methods to respond to each change made to your fetched results, and animate the changes as they occur in your table. However, as the NSFetchedResultsControllerDelegate documentation states:


为所有更改设置动画可能在计算上昂贵。不必单独响应更改(如典型使用中所示),您只需实现controllerDidChangeContent:(在所有待处理的更改已处理后发送给委托)以重新加载表视图

It may be computationally expensive to animate all the changes. Rather than responding to changes individually (as illustrated in "Typical Use"), you could just implement controllerDidChangeContent: (which is sent to the delegate when all pending changes have been processed) to reload the table view

因此,如果您要进行大量更改,则可以实现controllerDidChangeContent并使用 [self .tableView reloadData]

So if you're doing a bunch of changes, you can just implement controllerDidChangeContent and respond to all of them at once using something like [self.tableView reloadData].

这篇关于是否为Core Data的获取结果控制器实现委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆