2009-11-25 4 views
4

Afetr вставив новую запись в мой магазин CoreData используя NSFetchedResultsController, когда я затем попытаться отобразить данные в сгруппированных UITableView аварий приложение со следующей ошибкой»NSFetchedResultsController ОШИБКА:

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

Я добавил . раздел ключевое значение для 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

Doh! Нашел мою проблему: я перевыполнил sortDescriptors

0

Но вы просачиваете отдельные sortDescriptors sortByGroupName и так далее. Вы также должны освободить их.

Смежные вопросы