Detect changes in a specific core data table
I'm using a NSFetchedResultsControllerDelegate to detect change in a table view that print "Events". But those "Events" are linked to an "Association", including a "isFollowed" number (if the Assiciation.isFollow == 1
, then we print the event, otherwise we don't). We can change these isFollow BOOL, but the NSFetchedResultsControllerDelegate detect changes in "Events", not in "Association". So I'm using this code
- (void) viewWillAppear:(BOOL)animated{
//[self setMyFetchedResultsController:nil];
NSError *error = nil;
[myFetchedResultsController performFetch:&error];
[[self myTableView] reloadData];
}
to reload each time the table. The problem is that it is not very efficient, because it updates each time the controller, and not just when it's useful. So I wanted to know if there is a solution to detect changes in a specific row in a specifi开发者_如何转开发c table in core data, or if you are thinking to a better way.
Thanks, Niels
You could monitor save notifications (see NSManagedObjectDidSaveNotification docs) and crawl through their results to check if any Associations were changed. This approach is inherently inefficient.
A better approach though would probably be to have a delegate callback from the view controller modifying the association, and force the update of your table cell / fetched results controller after that.
I think it would appropriate in this instance to simply update the individual table cell representing the Event w/ the followed or unfollowed association. In the case of bulk updates though it would be best to simply reload the entire table.
精彩评论