Objective c NSFetchRequestController在iOS5上工作,在iOS4.3上崩溃
我一直在尝试在一个至少需要iOS 4.3的项目中实现核心数据。我让代码在iOS 5上正常工作,但在iOS 4.3上尝试时,代码崩溃的原因如下:Objective c NSFetchRequestController在iOS5上工作,在iOS4.3上崩溃,objective-c,core-data,ios4,nsfetchedresultscontroller,Objective C,Core Data,Ios4,Nsfetchedresultscontroller,我一直在尝试在一个至少需要iOS 4.3的项目中实现核心数据。我让代码在iOS 5上正常工作,但在iOS 4.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
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之后)
建议
更新:
似乎当我在多任务栏中关闭我的应用程序,然后重新启动它时,带有ÄÄÖ的顺序是正确的(使用caseInsensitiveCompare)。但只有在第一次重新启动之后。第一次发布时仍然是错误的…您使用的是章节索引标题吗?这似乎就是这个错误所指的 只需添加:
-(NSString *)controller:(NSFetchedResultsController *)controller
sectionIndexTitleForSectionName:(NSString *)sectionName {
return sectionName;
}
到您的表视图控制器。是否使用节索引标题?这似乎就是这个错误所指的 只需添加:
-(NSString *)controller:(NSFetchedResultsController *)controller
sectionIndexTitleForSectionName:(NSString *)sectionName {
return sectionName;
}
这实际上并没有解决localizedCaseInsensitiveCompare的问题,但它确实解决了caseInsensitiveCompare的错误顺序。所以这是一场胜利!因为我的应用程序只在瑞典语中本地化,所以它似乎可以自行解决问题。谢谢。这实际上并没有解决本地化caseInsensitiveCompare的问题,但它确实解决了caseInsensitiveCompare的错误顺序。所以这是一场胜利!因为我的应用程序只在瑞典语中本地化,所以它似乎可以自行解决问题。谢谢