我应该在processContentChanges中做什么:?

时间:2016-04-08 13:00:36

标签: ios core-data nsnotifications

这是我应用的processContentChanges:方法,由NSPersistentStoreDidImportUbiquitousContentChangesNotification触发:

- (void)processContentChanges:(NSNotification *)notification {    
    [self.managedObjectContext performBlock:^{
        // Merge incoming data updates in the managed object context
        [self.managedObjectContext mergeChangesFromContextDidSaveNotification:notification];

        // Post notification to trigger UI updates
#warning What do I actually do here?
    }];
}

我在整个应用程序中使用NSFetchedResultsController,以便在通过iCloud从其他设备收到更改时,UI会自动更新。这一切似乎都有效,但评论说// Post notification to trigger UI updates已经存在于模板方法中。我真的应该在这里做些什么,还是我可以安全地按照他们的方式离开?

1 个答案:

答案 0 :(得分:0)

好吧,虽然我还没有确认这一点,但我认为只要满足以下条件,就不需要在此方法中做任何其他事情:

  1. 您可以根据模板正确实施NSPersistentStoreDidImportUbiquitousContentChangesNotification,以便将新内容合并到托管对象上下文
  2. 您的内容是使用NSFetchedResultsController个对象
  3. 生成的
  4. 您的viewControllers符合NSFetchedResultsControllerDelegate协议,并实施controllerWillChangeContent:controllerDidChangeContent:controller:didChangeObject:atIndexPath:forChangeType:newIndexPath
  5. 在这些方法中,相应地更新您的视图以显示新内容,删除已删除的内容以及更新更改的内容。
  6. 如果您有任何使用CoreData而没有NSFetchedResultsController的对象,那么您可能需要通过在CoreData发布NSPersistentStoreDidImportUbiquitousContentChangesNotification时手动重新获取数据来更新这些对象。