Why NSFetchedResultsController is not being updated with new data?
Generally you should not need to save the changes if you are dealing with a single NSManagedObjectContext
for both the NSFetchedResultsController
and the UIViewController
that is making the changes.
That does not apply if you have more than one NSManagedObjectContext
.
Assuming you have one NSManagedObjectContext
, I would make sure you have the delegate set on the NSFetchedResultsController
and put break points in the delegate methods to see if you are getting any callbacks at all.
I would also use the debugger and print out the pointers for the NSManagedObject(s) you are working with and make sure they are the same. If they are not then it would point to an issue with the NSManagedObjectContext
.
Response #1
Hmmm, still a little fuzzy. Are you saying the number of sections is incorrect?
Based on your code posted you are simply retrieving the NSManagedObject
instances from the NSFetchedResultsController
. Perhaps there is some confusion as to what that is?
The NSFetchedResultsController
is merely a container that has one or more sections. Those sections are also just a container that holds one or more NSManagedObject instances. Those are the same instances of NSManagedObject
that you would access anywhere else in your application (assuming a single NSManagedObjectContext
design).
Therefore if you change the data in a NSManagedObject
anywhere in your application it will be updated in the NSFetchedResultsController
because it is the same object, not a copy but the exact same object.
So this leads to a couple of questions:
- How are you changing the author's name in this other view?
- Is the author name in the cell old or just the section header?
- What do your delegate methods look like?
- Are you certain that your
-[UITableViewDatasource tableView: titleForHeaderInSection:]
is firing after you return from the edit? - What
NSFetchedResultsControllerDelegate
methods are firing upon the return?
Response #2
Are you implementing -controller: didChangeSection: atIndex: forChangeType:
? If not, please do so and tell me if it fires. If it does fire, when does it fire? Before or after the call to -[UITableViewDatasource tableView: titleForHeaderInSection:]
?
Response #3
This is starting to sound like an Apple bug.
A couple of thoughts:
- What happens if you do a -performFetch: after the author is tickled? I wonder if that would work.
- I strongly suggest that you create a test case for this. You can then submit it to Apple for a radar (vital) and I can play with the test also and see if there is a clean solution.