Afetr NSFetchedResultsController를 사용하여 CoreData 저장소에 새 레코드를 삽입하면 그룹화 된 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