Hi I currently have a table view which is being filled via Core Data.
I am limiting the results using NSPredicate so that only items with the same OrderNumber are displayed in the tableView.
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"orderNumber == %@", orderNumberLabel.text];
NSLog(@"predicate is: %@",predicate);
[fetchRequest setPredicate:predicate];
Once the form for entering an order has been completed a button is pressed [save order] and the orderNumber is then incremented by one, as well as the orderNumberLabel.
What I expect to happen is that the tableView should then be empty as the new orderNumber has no entries in the sql database. However this does not occur and calling [myTableView reloadData]; does not resolve it either.
However, if I quit the project and re-run it I have the new orderNumber and an empty tableView. So there is something happening at run-time with the fetch request and predicate being set that I need to try & replicate with a call in my saveOrderButtonPressed method. Only problem is that I don’t know how to do this, could someone help please?
Occassionally I have also been getting the following error after quitting and re-running the app after entering orders. It is related to me changing the orderNumber but I think it will disappear once I am updating the predicate/fetchRequest. I also need some guidance on this, will I need to disable caching?
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason:'FATAL ERROR: The persistent cache of section information does not match
the current configuration. You have illegally mutated the NSFetchedResultsController's
fetch request, its predicate, or its sort descriptor without either disabling
caching or using +deleteCacheWithName:'
You are right to use a
NSFetchedResultsController. It is made exactly for the use you describe.As the error message says, you can set the cache of the NSFetchedResultsController to
nilto completely disable caching – not a big performance hit when you have so few items. Or you can use+deleteCacheWithName:with the name you assigned to the cache. Only then can you change the fetch request (e.g. the predicate) and then you must doperformFetch:again. Hopefully you have the delegate hooked up so your table view is automatically refreshed.You don’t say you are doing any of the things that will cause problems (changing predicate, sort order etc.) – are you sure you’re not?