我有一个包含期刊栏目名称的文章数据库。一篇文章是“应用物理学杂志”,另一篇是“应用物理学报”。当我使用
[[NSSortDescriptor alloc] initWithKey:@"Journal" ascending:YES elector:@selector(caseInsensitiveCompare:)]
获取数据,它给我错误信息。
The fetched object at index 501 has an out of order section name 'JOURNAL OF APPLIED PHYSICS. Objects must be sorted by section name'
我已经使用不区分大小写的比较了,为什么这不起作用?帮助
======= 用于获取数据的代码=======
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Article"
inManagedObjectContext:SharedMOC];
[fetchRequest setEntity:entity];
NSSortDescriptor *journalSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Journal"
ascending:ascending
selector:@selector(caseInsensitiveCompare:)];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:journalSortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSFetchedResultsController *a = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:SharedMOC
sectionNameKeyPath:[self selectedSortSection]
cacheName:cacheName];
答案 0 :(得分:1)
我的直觉说不是:
[fetchRequest setSortDescriptors:[self getSortDescriptor]];
你应该写:
[fetchRequest setSortDescriptors:sortDescriptors];