我有一個包含日記部分名稱的文章數據庫。一篇是「應用物理雜誌」,另一篇是「應用物理雜誌」。當我使用在索引501處的獲取對象具有亂序部分名稱'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];
Q1:你如何創建你的獲取請求? (請輸入代碼) Q2:是「@」日記「」您正在排序的屬性的名稱? – octy 2011-05-30 20:42:41
見上文。 Q2:是的 – Dan 2011-05-30 20:57:49
謝謝。在那種情況下,'Journal'是一個NSString?如果'Journal'是另一個實體,則例如,您的keypath應該是'Journal.name'。 – octy 2011-05-30 20:59:29