2011-12-23 3 views
1

Я пытаюсь реализовать Core Data в проекте, для которого требуется минимум iOS 4.3. Я получаю код, чтобы работать без каких-либо проблем на прошивке 5, но при попытке его с прошивкой 4.3 он выходит из строя со следующей причиной:NSFetchRequestController работает на iOS5, авария на iOS4.3

Unresolved error Error Domain=NSCocoaErrorDomain Code=134060 "The operation couldn’t be completed. (Cocoa error 134060.)" UserInfo=0x4fb59b0 {reason=The fetched object at index 4 has an out of order section name 'Å. Objects must be sorted by section name'}, { 
reason = "The fetched object at index 4 has an out of order section name '\U00c5. Objects must be sorted by section name'"; 

Вот мой код:

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

fetchRequest.entity = [NSEntityDescription entityForName:@"Exhibitor" 
            inManagedObjectContext:self.managedObjectContext]; 

// Edit the sort key as appropriate. 
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" 
                   ascending:YES 
                   selector:@selector(caseInsensitiveCompare:)]; 

fetchRequest.sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; 

// 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:self.managedObjectContext 
                 sectionNameKeyPath:@"firstLetter" 
                 cacheName:nil]; 
aFetchedResultsController.delegate = self; 
self.fetchedResultsController = aFetchedResultsController; 

NSError *error = nil; 
if (![self.fetchedResultsController performFetch:&error]) { 
    /* 
    Replace this implementation with code to handle the error appropriately. 

    abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
    */ 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
} 

    return __fetchedResultsController; 
} 

Если я в моем sortDesctriptor предпочитает использовать caseInsensitivecompare: вместо localizedCaseInsensitiveCompare: он не падает, но порядок неправильный (так как мне нужно, чтобы Ä Ö был внизу, а не после A и O).

Предложения?

UPDATE: Кажется, когда я убить мое приложение в многозадачном баре, а затем возобновить его, заказ с Aao правильно (с использованием caseInsensitiveCompare). Но только после первого перезапуска. Это все еще неправильно при первом запуске ...

ответ

1

Вы используете заголовки разделов раздела? Кажется, что эта ошибка имеет в виду.

Просто добавьте:

-(NSString *)controller:(NSFetchedResultsController *)controller 
      sectionIndexTitleForSectionName:(NSString *)sectionName { 
    return sectionName; 
} 

к контроллеру табличного.

+0

Это на самом деле не решило проблему с localizedCaseInsensitiveCompare, но она действительно разрешила неправильный порядок с caseInsensitiveCompare. Так вот победа! Поскольку мое приложение локализовано только на шведском языке, оно, похоже, решает сам. Благодарю. – Nings

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