相关疑难解决方法(0)

NSFetchedResultsController在performFetch上崩溃:使用缓存时

我使用NSFetchedResultsController来显示一堆对象,这些对象使用日期进行分区.在全新安装中,它完全正常工作,对象显示在表格视图中.然而,似乎当应用程序重新启动时,我遇到了崩溃.我在初始化NSFetchedResultsController时指定了一个缓存,当我不这样做时,它完美地工作.

以下是我创建NSFetchedResultsController的方法:

- (NSFetchedResultsController *)results {
    // If we are not nil, stop here
    if (results != nil)
        return results;

    // Create the fetch request, entity and sort descriptors
    NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext];
    NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"utc_start" ascending:YES];
    NSArray *descriptors = [[NSArray alloc] initWithObjects:descriptor, nil];

    // Set properties on the fetch
    [fetch setEntity:entity];
    [fetch setSortDescriptors:descriptors];

    // Create a fresh fetched results controller
    NSFetchedResultsController *fetched = [[NSFetchedResultsController alloc] initWithFetchRequest:fetch managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"day" …
Run Code Online (Sandbox Code Playgroud)

iphone core-data objective-c nsfetchedresultscontroller

47
推荐指数
5
解决办法
2万
查看次数