Implement delegates for Core Data's fetched results controller or not

纵饮孤独 提交于 2019-12-24 02:33:27

问题


What advantage is there to implementing the four delegate methods:

  • (void)controllerWillChangeContent:(NSFetchedResultsController *)controller

  • (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)controllerDidChangeContent:(NSFetchedResultsController *)controller

rather than implement:

  • (void)controllerDidChangeContent:(NSFetchedResultsController *)controller

Any help appreciated // :)


回答1:


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:

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

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].



来源:https://stackoverflow.com/questions/2946385/implement-delegates-for-core-datas-fetched-results-controller-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!