Iphone NSFetchedResultsController错误:

Iphone NSFetchedResultsController错误:,iphone,core-data,nsfetchedresultscontroller,Iphone,Core Data,Nsfetchedresultscontroller,Afetr使用NSFetchedResultsController将新记录插入到我的CoreData存储中,当我尝试在分组UITableView中显示数据时,应用程序崩溃,出现以下错误“ 我已将节键值添加到sortDescriptors中,但没有帮助。以下是我的代码: - (NSFetchedResultsController *)fetchedResultsController { if (fetchedResultsController != nil) { return fetch

Afetr使用NSFetchedResultsController将新记录插入到我的CoreData存储中,当我尝试在分组UITableView中显示数据时,应用程序崩溃,出现以下错误“

我已将节键值添加到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

Doh!发现了我的问题:我过度发布了sortDescriptors

但是你正在泄漏单个sortDescriptors sortByGroupName,等等。你也应该发布它们

- (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;