I’m using NSFetchedResultsController for my table view. I call -performFetch inside my controller’s -viewDidLoad method.
Sometimes my controller gets unloaded and then re-loaded, resulting in another call to -viewDidLoad and -performFetch. I found that this was causing an error: “NSFetchedResultsController error: section ‘(null)’ not found in controller”. I found that calling -performFetch multiple times like this was causing the problem, and modified my -viewDidLoad: method to do the following:
if( fetchedResCtrlr.fetchedObjects == nil )
{
NSError *error;
if ( ![fetchedResCtrlr performFetch:&error] )
...
}
Being new to Core Data, I’m wondering if this is the correct action to take. Should I actually be able to call -performFetch: more than once without error? Should I be doing something in -viewDidUnload:?
Thanks!
Normally, there is nothing that needs to be done with the
NSFetchedResultsControllerin the-viewDidUnload:. Also, checking for nil against the-fetchedObjectsis normally not worth it. Sounds like your code has other flow issues. Calling-performFetch:more than once would only harm performance on its own, without any other ill effects.