Jos*_*hua 5 iphone core-data nsfetchedresultscontroller ios
CoreData: error: (NSFetchedResultsController) The fetched object at index 72 has an out of order section name '??. Objects must be sorted by section name'
I am using the following code to sort by book title field and display book title's first upper case letter as the section name in a UITableViewController.
The code runs perfectly in all languages except of Thai. I read on the Internet that there are special non US characters causing such issues (i.e. Æ), but I didn't find any solution yet.
See gschandler response on The fetched object at index [i] has an out of order section name 'å
Code of FRC is
NSFetchedResultsController *aFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:managedObjectContext
sectionNameKeyPath:@"titleFirstLetter"
cacheName:nil];
Run Code Online (Sandbox Code Playgroud)
Code of firstLetter is:
- (NSString *)titleFirstLetter {
// support UTF-16:
NSString* val = [self.title substringWithRange:[self.title rangeOfComposedCharacterSequenceAtIndex:0]];
return [val uppercaseString];
}
Run Code Online (Sandbox Code Playgroud)
Any suggestions?
小智 5
您必须添加一个排序描述符,该描述符对 sectionNameKeyPath 所做的相同属性进行排序。
NSSortDescriptor *sort = [[NSSortDescriptor alloc]initWithKey:@"titleFirstLetter" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sort,nil]];
[fetchRequest setFetchBatchSize:20];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2265 次 |
| 最近记录: |