2016-04-08 47 views
0

這是我的應用程序的processContentChanges:方法,它是通過NSPersistentStoreDidImportUbiquitousContentChangesNotification觸發:我應該在processContentChanges中做什麼:?

- (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 S以便UI時,從其他設備通過iCloud中收到的變化自動更新。這一切似乎都奏效,但// Post notification to trigger UI updates的評論已經存在於模板方法中。我是否應該在這裏做點什麼,或者我可以安全地讓事情保持原樣?

回答

0

好吧,雖然我還沒有這個我不認爲確認有其他任何需要在這個方法中,只要滿足以下標準進行:

  1. 您實現NSPersistentStoreDidImportUbiquitousContentChangesNotification正確地按照該模板,使得新的內容被合併到管理對象上下文是使用NSFetchedResultsController對象
  2. 你viewControllers符合所述NSFetchedResultsControllerDelegate協議生成
  3. 你的內容,並且實現controllerWillChangeContent:controllerDidChangeContent:controller:didChangeObject:atIndexPath:forChangeType:newIndexPath
  4. 在這些方法中,相應地更新您的視圖以顯示新內容,刪除已刪除的內容並更新已更改的內容。

如果您有使用CoreData沒有NSFetchedResultsController任何對象,那麼你可能需要手動更新這些重新獲取數據時NSPersistentStoreDidImportUbiquitousContentChangesNotification由CoreData發佈。