我正在使用排序描述符设置 NSFetchedResultsController
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@”name” ascending:YES selector:@selector(caseInsensitiveCompare:)];
和部分
aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@”name” cacheName:nil];
然后我还像这样设置表格视图部分的委托:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return [self.fetchedController sectionIndexTitles];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
return [self.fetchedController sectionForSectionIndexTitle:title atIndex:index];
}
有时,当我插入对象时,我会收到错误消息“索引 X 处的获取对象有一个乱序的部分名称'某物。对象必须按部分名称排序'”;
我正在插入数千行。当错误发生时,总是相同的大小写:我有 10 个对象称为相同的东西,但有些是大写的,有些是小写的。示例:nameexample、nameExample、nameEXAMPLE、nameexample、nameExample 等。
知道为什么我会收到错误,我该如何解决这个问题?我让它不区分大小写的原因是因为我的部分是基于第一个字母的,如果我不区分大小写,我会得到部分'a'和部分'A'。