开发者

NSFetchedResultsController delegate methods not firing after mergeChangesFromContextDidSaveNotification

开发者 https://www.devze.com 2023-01-20 22:18 出处:网络
Been browsing through the posts similar to this one but none answered my problem. Like CoreDataBooks, I use a separate MOC for adding and editing items and observe the proper notifications, like so:

Been browsing through the posts similar to this one but none answered my problem.

Like CoreDataBooks, I use a separate MOC for adding and editing items and observe the proper notifications, like so:

- (void)addControllerContextDidSave:(NSNotification*)saveNotification {

  NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
  // Merging changes causes the fetched results controller to update its results
  [context mergeChangesFromContextDidSaveNotification:saveNotification];
  NSLog(@"merging changes in rootview");
}

When I do a save, it's observed correctly. Debugging the notification shows the right context, and debugging the context shows the just added item. The log message also prints just fine. But nothing happens. None of the delegate methods of the NSFetchedResultsController fire, nor is the table view updated.

I tried no cache or clearing it. I've tried reloadData on the tableView, but nothing. When I quit the app and restart, it shows up fine.

UPDATE: The notification does indeed contain the right context as its object, which contains the correct item, but the userInfo hash has nothing in it:

userInfo = {
  inserted = "{(\n)}";
  updated开发者_开发百科 = "{(\n)}";
}

So it looks like the notification doesn't have any changes in it, despite having the correct context with the changed item.... hmmmm.


And the award for dumbest mistake goes toooooo ... Christoph!!

The reason the notification was not showing anything was that I had forgotten to take out a save on the separate MOC before calling the delegate that set up the notification and then saved again.

Since the MOC was just saved, the second save had no changes and thus the notification stayed empty. Removing the first save, as I should have done much earlier, did fix the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消