我需要澄清一些来自苹果文档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您的回复。你能指定一下你的意思吗?“你不必指定它们的确切字段,但排序顺序应该是相同的。”?小样本可能会有用;-)谢谢。 –
谢谢乔迪。您对核心数据有很好的了解。干杯。 –