I have an issue with my table view not updating when I programmatically change some existing managed object property. I would expect my NSFetchedResultsControllerDelegate
to be called in such case, but it isn't.
Apple doc says:
An instance of
NSFetchedResultsController
uses methods in this protocol to notify its delegate that the controller’s fetch results have been changed due to an add, remove, move, or update operations.
In more details, my managed object as an int property called status
that takes values from an enum
. My table view only display those objects which have their status
equal to upToDate
(one of the enum's values). To do so, my FetchedResultController has a predicate that tests for that status:
predicate = [NSPredicate predicateWithFormat:@"doc.status == %d", upToDate];
It works fine, but updates are not reflected when I change an out-of-date object back to status upToDate
. My code is modified from Apple's template.
Here is what I tried:
myObject.status = [NSNumber numberWithInt:upToDate];
[managedObjectContext save:nil];
[managedObjectContext processPendingChanges];
[myTableView reloadData];
And finally, I managed to have my table view update with a call to:
[fetchedResultsController performFetch:&error];
[myTableView reloadData];
But even then, none of my NSFetchedResultsControllerDelegate
methods get called, in contradiction with Apple's doc. Additionally, no smooth animation happen.
I expected controllerWillChangeContent:
, controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
, and controllerDidChangeContent:
to be called.
I suppose I missed something, possibly something obvious, but I can't see what. Does performFetch:
need to be called every time some managed object potentially changes? When does the NSFetchedResultsControllerD
really call its delegate?
Thanks.