首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSFetchedResultsController错误:

NSFetchedResultsController错误:
EN

Stack Overflow用户
提问于 2009-11-26 03:37:05
回答 2查看 2.4K关注 0票数 4

在使用NSFetchedResultsController向我的CoreData存储中插入新记录后,当我尝试在分组的UITableView中显示数据时,应用程序崩溃,并显示以下错误:

代码语言:javascript
复制
NSFetchedResultsController ERROR: The fetched object at index 5 has an out of order section name 'Navigation. Objects must be sorted by section name'

我已经将section key值添加到sortDescriptors中,但它没有帮助。下面是我的代码:

代码语言:javascript
复制
- (NSFetchedResultsController *)fetchedResultsController {

if (fetchedResultsController != nil) {
    return fetchedResultsController;
}

/*
 Set up the fetched results controller.
 */
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Item" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];

// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];

// Edit the sort key as appropriate.
NSSortDescriptor *sortByGroupName = [[NSSortDescriptor alloc] initWithKey:@"group.groupName" ascending:NO];
NSSortDescriptor *sortByIsMandatory = [[NSSortDescriptor alloc] initWithKey:@"isMandatory" ascending:NO];
NSSortDescriptor *sortByItemName = [[NSSortDescriptor alloc] initWithKey:@"itemName" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortByGroupName, sortByIsMandatory, sortByItemName, nil];

[fetchRequest setSortDescriptors:sortDescriptors];

// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"group.groupName" cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

[aFetchedResultsController release];
[fetchRequest release];
[sortDescriptors release];
[sortDescriptors release];

return fetchedResultsController;

}

这里我漏掉了什么?

谢谢--

Jk

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-11-26 06:35:16

多!找到我的问题了:我过度发布了sortDescriptors

票数 2
EN

Stack Overflow用户

发布于 2011-05-02 04:48:27

但是您正在泄漏单个sortDescriptors sortByGroupName,等等。你也应该释放它们。

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

https://stackoverflow.com/questions/1799451

复制
相关文章

相似问题

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