I have a UITableView that displays a subset of a large number of objects called Documents. A subset is defined by another Selection object. Selected names, an ordered list of documents.
It works fine, except when I want to change the displayed selection at runtime. I get only an empty list.
Basically, I need to change the predicate that is executed by my NSFetchedResultsController so that the new predicate uses a different Selection. I could not get it to work. My last attempt is to completely get rid of NSFetchedResultsController and redistribute it:
- (void) displaySelection:(Selection *)aSet
{
self.currentSelection = aSet;
self.fetchedResultsController = nil;
[self fetchedResultsController];
[self.tableView reloadData];
}
And, of course, the NSFetchedResultsController collector does the right thing:
- (NSFetchedResultsController *)fetchedResultsController
{
if (fetchedResultsController != nil) { return fetchedResultsController; }
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"DocInSelection" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"selection.identifier like %@", currentSelection.identifier];
[fetchRequest setPredicate:predicate];
<snip>
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
<snip>
return fetchedResultsController;
}
, . displaySelection:, .
NSFetchedResultsController - UITableView
, NSFetchedResultsController. , NSFetchedResultsController (, , ...). : "" UITableView, NSFetchedResultsController, "switch" ( ) .
, , " " " ", DocInSelection, "ordering" , - .
.