NSFetchedResultsController刷新以获取新数据

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实例执行新请求.

Mar*_*n R 5

更改搜索条件后,必须将实例变量设置self.fetchedResultsControllernil,以便下一次调用"lazy getter"函数创建一个带有更改谓词的新FRC.像这样的东西:

self.fetchedResultsController = nil;
[self.fetchedResultsController performFetch:&error];
[self.tableView reloadData];
Run Code Online (Sandbox Code Playgroud)