我有一个UITableView,它显示了大量名为"Documents"的实体的子集.该子集由另一个实体"选择"定义.选择是命名的,有序的文档列表.
它工作正常,除非我想在运行时更改显示的选择.我只得到一个空白列表.
基本上,我需要更改我的NSFetchedResultsController所持有的谓词,以便新谓词使用另一个Selection.我无法让它发挥作用.我的最后一次尝试是完全摆脱NSFetchedResultsController并重新分配它:
- (void) displaySelection:(Selection *)aSet
{
self.currentSelection = aSet;
self.fetchedResultsController = nil;
// methods here don't all use the property but directly the ivar, so we must trigger the getter
[self fetchedResultsController];
[self.tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
当然,NSFetchedResultsController getter做正确的事情:
- (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 …Run Code Online (Sandbox Code Playgroud) cocoa-touch core-data uitableview master-detail nsfetchedresultscontroller