在使用NSFetchedResultsController向我的CoreData存储中插入新记录后,当我尝试在分组的UITableView中显示数据时,应用程序崩溃,并显示以下错误:
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中,但它没有帮助。下面是我的代码:
- (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
发布于 2009-11-26 06:35:16
多!找到我的问题了:我过度发布了sortDescriptors
发布于 2011-05-02 04:48:27
但是您正在泄漏单个sortDescriptors sortByGroupName,等等。你也应该释放它们。
https://stackoverflow.com/questions/1799451
复制相似问题