2009-11-25 39 views
4

Afetr插入新記錄到使用NSFetchedResultsController,當我再嘗試用下面的錯誤」NSFetchedResultsController錯誤:

NSFetchedResultsController ERROR: The fetched object at index 5 has an out of order section name 'Navigation. Objects must be sorted by section name' 

我已經加入了顯示在分組UITableView的應用程序崩潰的數據我CoreData店。部分鍵值到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

回答

2

衛生署!發現我的問題:我過度發佈sortDescriptors

0

但是你泄漏單個sortDescriptors sortByGroupName,等等。你也應該釋放這些。

相關問題