Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload