作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个包含期刊章节名称的文章数据库。一篇是《Journal of Applied Physics》,一篇是《JOURNAL OF APPLIED PHYSICS》。当我使用
[[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];
最佳答案
我的直觉告诉我,而不是:
[fetchRequest setSortDescriptors:[self getSortDescriptor]];
你应该写:
[fetchRequest setSortDescriptors:sortDescriptors];
关于cocoa-touch - 在索引 501 处获取的对象有一个乱序的部分名称 'JOURNAL OF APPLIED PHYSICS. Objects must be sorted by section name',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6180317/
我是一名优秀的程序员,十分优秀!