首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >performFetch上的NSFetchedResultsController崩溃:使用缓存时

performFetch上的NSFetchedResultsController崩溃:使用缓存时
EN

Stack Overflow用户
提问于 2010-04-26 04:09:11
回答 9查看 24.9K关注 0票数 47

我使用NSFetchedResultsController来显示一组对象,这些对象使用日期进行分区。在全新安装时,它可以完美地工作,并且对象会显示在表视图中。然而,似乎当应用程序重新启动时,我会崩溃。我在初始化NSFetchedResultsController时指定了一个缓存,如果不这样做,它就会完美地工作。

下面是我创建NSFetchedResultsController的方法:

代码语言:javascript
运行
复制
- (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" cacheName:@"Events"];
    fetched.delegate = self;
    self.results = fetched;

    // Release objects and return our controller
    [fetched release];
    [fetch release];
    [descriptor release];
    [descriptors release];
    return results;
}

以下是应用程序崩溃时我收到的消息:

代码语言:javascript
运行
复制
FATAL ERROR: The persistent cache of section information does not match the current configuration.  You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FATAL ERROR: The persistent cache of section information does not match the current configuration.  You have illegally mutated the NSFetchedResultsController's fetch request, its predicate, or its sort descriptor without either disabling caching or using +deleteCacheWithName:'

我真的不知道为什么会这样说,因为我不相信我做了什么特别的事情会导致这种情况。唯一的潜在问题是节标题(day),我在创建新对象时构造如下:

代码语言:javascript
运行
复制
// Set the new format
[formatter setDateFormat:@"dd MMMM"];

// Set the day of the event
[event setValue:[formatter stringFromDate:[event valueForKey:@"utc_start"]] forKey:@"day"];

正如我所提到的,如果不涉及缓存,所有这些都可以正常工作。感谢任何人的帮助!

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2709768

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档