MagicalRecord - 如何清除nsfetchedresultscontroller缓存并更改谓词

时间:2015-09-16 18:54:47

标签: ios nsfetchedresultscontroller nsfetchrequest magicalrecord

以下作品一次:

self.fetchedResultsController = [Cat MR_fetchAllSortedBy:@"age" ascending:YES withPredicate:predicate groupBy:@"age" delegate:self inContext:[NSManagedObjectContext MR_defaultContext]];

但是设置新谓词并再次进行此调用不会刷新数据。如何清除缓存并强制fetchedResultsController获取新数据?

1 个答案:

答案 0 :(得分:0)

您必须更改fetchedResultsController的谓词或sortDesctriptors属性。

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"startDate" ascending:YES];
[[fetchedResultsController fetchRequest] setSortDescriptors:@[sortDescriptor]];

[[fetchedResultsController fetchRequest] setPredicate:predicate];

..而且你再次获取

if (![[self fetchedResultsController] performFetch:&error]) {
    // Handle you error here
}

..并刷新你的tableView

[self.tableView reloadData];