views:

1596

answers:

3

I'm finishing up the Core Data tutorial, and it suggests trying to convert to using a NSFetchedResultsController. So I've got it so that I can query the existing data, but when I add a row at the beginning, tableView:cellForRowAtIndexPath calls NSFetchedResultsController.objectAtIndexPath, but that still returns the old zeroth object instead of the new one. Is there something I need to do to flush that data?

+2  A: 

Nobody has answered yet, so I'll add my guess. It looks like this link might be relevant. The suggestion there is that calling either of these two methods should get an update for you:

-[NSManagedObjectContext processPendingChanges]
-[NSManagedObjectContext save]

Perhaps the documentation for NSManagedObjectContext will be useful.

Naaff
Actually, I was already doing the [managedContext save]; but there was a clue in there.
Paul Tomblin
+2  A: 

There was a clue in the link that Naaf provided. Turns out that after doing the save, I needed to call -[NSFetchedResultsController performFetch] again.

Paul Tomblin
+1  A: 

Have you set your view controller as the fetched results controller's delegate and implemented the NSFetchedResultsControllerDelegate protocol? If so, you should not have to perform the fetch again, the fetched results controller will invoke the delegate methods in response to changes.

(Note, though, the caution in NSFetchedResultsController documentation regarding the implementation of the table view data source methods.)

mmalc
Paul Tomblin
What is the exception, and in what method?
mmalc