【发布时间】:2012-08-28 06:24:38
【问题描述】:
我需要 Apple 文档中的一些说明
获取请求必须至少有一个排序描述符。如果 控制器生成节,数组中的第一个排序描述符 用于将对象分组;它的键必须是 与 sectionNameKeyPath 相同或使用其键的相对排序必须 使用 sectionNameKeyPath 匹配。
我正在使用NSFetchedResultsController 以下列方式包含部分
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:mainContext
sectionNameKeyPath:@"paymentDate"
cacheName:nil];
据我了解,我在NSFetchedResultsController 中传递的NSFetchRequest 必须至少有一个排序描述符。但是由于我使用sections,所以排序描述符必须如下:
[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 错误:在索引 X 处获取的对象有一个 乱序节名 Y。对象必须按节名排序'
就我而言,使用[NSSortDescriptor sortDescriptorWithKey:@"paymentDate" ascending:YES],它可以让我克服这个问题。也许我只是幸运;)。
但是,这是什么意思或者使用其键的相对排序必须与使用 sectionNameKeyPath 的相对排序相匹配?你能给我解释一下吗?
提前谢谢你。
【问题讨论】:
标签: ios core-data nsfetchedresultscontroller nsfetchrequest