Mat*_*der 1 core-data nsfetchedresultscontroller
请指导我正确的方式.
我实现了这段代码来获取我的对象:
- (NSFetchedResultsController *)fetchedResultsController {
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSPredicate *predicate = nil;
if (self.selectedCategory)
{
predicate = [NSPredicate predicateWithFormat:@"ANY category_ids.category_id == %@", self.selectedCategory];
}
_fetchedResultsController = [EyeArtist fetchAllGroupedBy:nil withPredicate:predicate sortedBy:@"artist_id" ascending:NO delegate:self];
return _fetchedResultsController;
}
Run Code Online (Sandbox Code Playgroud)
因此,当app在第一次运行时,fetch在没有谓词的情况下工作,所以在第二次我需要使用谓词进行新的提取.
我点击按钮并设置字符串self.selectedCategory,但我不知道如何从 - (NSFetchedResultsController*)fetchedResultsController重新获取数据;
所以我想它必须像对fetchedResultsController实例执行新请求.
更改搜索条件后,必须将实例变量设置self.fetchedResultsController为nil,以便下一次调用"lazy getter"函数创建一个带有更改谓词的新FRC.像这样的东西:
self.fetchedResultsController = nil;
[self.fetchedResultsController performFetch:&error];
[self.tableView reloadData];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1833 次 |
| 最近记录: |