我需要澄清一些來自蘋果文檔NSFetchedResultsController:DOC澄清需要
The fetch request must have at least one sort descriptor. If the controller generates sections, the first sort descriptor in the array is used to group the objects into sections; its key must either be the same as sectionNameKeyPath or the relative ordering using its key must match that using sectionNameKeyPath.
我以下列方式
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:mainContext
sectionNameKeyPath:@"paymentDate"
cacheName:nil];
使用NSFetchedResultsController
使用節當我從商務部瞭解, NSFetchRequest
我在NSFetchedResultsController
必須至少有一個排序描述符。但自從我使用的部分,那種描述符必須是這樣的:
[fetchRequest setSortDescriptors:[NSArray arrayWithObjects:
[NSSortDescriptor sortDescriptorWithKey:@"paymentDate" ascending:YES],
[NSSortDescriptor sortDescriptorWithKey:@"paymentCode" ascending:YES],
nil]];
如果我使用排序的描述,例如
[fetchRequest setSortDescriptors:[NSArray arrayWithObjects:
[NSSortDescriptor sortDescriptorWithKey:@"paymentCode" ascending:YES],
nil]];
我收到一個錯誤,如下面的
NSFetchedResultsController ERROR: The fetched object at index X has an out of order section name Y. Objects must be sorted by section name'
在我的情況,使用[NSSortDescriptor sortDescriptorWithKey:@"paymentDate" ascending:YES]
,它允許我克服這個問題。也許我只是幸運而已)。
但是,這是什麼意思或使用其鍵的相對順序必須與使用sectionNameKeyPath?你能給我一個解釋嗎?
預先感謝您。
+1您的回覆。你能指定一下你的意思嗎?「你不必指定它們的確切字段,但排序順序應該是相同的。」?小樣本可能會有用;-)謝謝。 –
謝謝喬迪。您對核心數據有很好的瞭解。乾杯。 –