简体   繁体   English

如何处理自定义结果视图的NSFetchedResultsControllerDelegate更新

[英]How do I Handle NSFetchedResultsControllerDelegate updates for custom results view

I am currently working on a CoreData based iPhone app with a map view that will have its annotations generated from an NSFetchedResultsController . 我目前正与该会从NSFetchedResultsController产生了注释的地图视图基于CoreData的iPhone应用程序。 The idea of the map view is that it will show a number of saved locations for the user. 地图视图的想法是它将为用户显示许多已保存的位置。

One of the advantages of using an NSFetchedResultsController is that I can set my map view as a delegate on NSFetchedResultsController and get notified of any changes made to the set of saved locations that happen on another device or on a website when the user is logged in. 使用NSFetchedResultsController的优点之一是,我可以将地图视图设置为NSFetchedResultsController上的委托,并在用户登录时收到在另一台设备或网站上发生的对保存位置集的任何更改的通知。

I am currently having a bit of trouble getting my head around how to deal with a number of different kinds of updates that are sent to my NSFetchedResultsControllerDelegate implementation. 我目前在解决如何处理发送到NSFetchedResultsControllerDelegate实现中的许多不同种类的更新方面有些麻烦。 The documentation: http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html doesn't seem to tell you how these different updates should be handled as it seems more geared towards integrating with a UITableView, which does most of the work. 文档: http : //developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html似乎并没有告诉您应该如何处理这些不同的更新,因为它似乎更适合与UITableView集成,这完成了大部分工作。

I am keeping an NSDictionary of my annotations that maps them to the NSIndexPath inside the result set. 我正在保存我的注释的NSDictionary,将其映射到结果集中的NSIndexPath。 The issue is, for example, when I receive 10 move, 3 insert and 4 delete updates, what order should I process these in? 问题是,例如,当我收到10次移动,3次插入和4次删除更新时,应按什么顺序处理这些更新? Some of these indexPaths will have a number of conflicting indices and the order in which they are processed will have an affect on the actual annotations I need to move, insert or delete. 其中一些indexPath将具有许多冲突的索引,它们的处理顺序将影响我需要移动,插入或删除的实际注释。 If I perform all the move updates first, then the insert indices will cause the final order to be different to their final order if I inserted first. 如果我先执行所有移动更新,则插入索引将导致最终顺序与如果我首先插入时的最终顺序不同。

Are there any existing small libraries/classes that will translate a set of indices prior to an update to a set of post update indices given those update messages? 是否存在任何现有的小型库/类,它们将在更新之前将一组索引转换为给定那些更新消息的一组更新后索引? If not, can anyone explain how this stuff works so I can write my own? 如果没有,谁能解释这玩意的工作原理,以便我自己写?

Any help will be greatly appreciated! 任何帮助将不胜感激!

The flow of the NSFetchedResultsControllerDelegate methods for one update cycle is like this: 一个更新周期的NSFetchedResultsControllerDelegate方法的流程如下:

  • controllerWillChangeContent: (called once) controllerWillChangeContent :(调用一次)
  • controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: (called X times) 控制器:didChangeObject:atIndexPath:forChangeType:newIndexPath :(称为X次)
  • controllerDidChangeContent: (called once) controllerDidChangeContent :(调用一次)

Every call to the didChangeObject method will be about just one object / indexPath. 每次对didChangeObject方法的调用都只会涉及一个对象/ indexPath。 You should apply the changes in the order that you receive them via those calls to didChangeObject. 您应该通过对didChangeObject的调用按收到的顺序应用更改。 That will keep them consistent. 这将使它们保持一致。

If you are using sections, you could also have calls to controller:didChangeSection:atIndex:forChangeType: intermixed with the object changed calls. 如果使用的是节,则可能还会有对controller:didChangeSection:atIndex:forChangeType:的调用与对象已更改的调用混在一起。

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

相关问题 如何在没有 NSFetchedResultsControllerDelegate 的情况下获取结果? - How to fetch results without NSFetchedResultsControllerDelegate? 如何使用Swift单元测试NSFetchedResultsControllerDelegate(controllerWillChangeContent和controllerDidChangeContent) - How do I unit test NSFetchedResultsControllerDelegate (controllerWillChangeContent and controllerDidChangeContent) using Swift 如何在多个ViewController中使用NSFetchedResultsControllerDelegate而不重复控制器代码? - How do I use NSFetchedResultsControllerDelegate in multiple ViewController without repeating the controller code? 当视图可见时,如何正确订阅位置更新? - How do I propertly subscribe to location updates when a View is visible? 如何在此表视图中搜索结果? - How do I search for results in this table view? 如何实现NSFetchedResultsControllerDelegate的默认值 - How to implement default of NSFetchedResultsControllerDelegate 如何对NSFetchedResultsControllerDelegate进行单元测试? - How to unit test NSFetchedResultsControllerDelegate? NSFetchedResultsControllerDelegate如何工作? - How does NSFetchedResultsControllerDelegate work? UICollectionView:如何在加载视图之前和之后处理更新? - UICollectionView: How to handle updates both before and after view is loaded? 如何获得通过情节提要添加到视图的控件的句柄? - How do I get a handle to a control that was added to a view via storyboard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM