gpt4 book ai didi

ios4 - NSFetchedResultsController 错误 : The fetched object at index X has an out of order section name Y. 对象必须按部分名称排序'

转载 作者:行者123 更新时间:2023-12-01 07:15:58 24 4
gpt4 key购买 nike

我正在 iphone 应用程序中实现搜索栏。我有 worker 列表,每个都有属性:名字、姓氏、公司。表 View 的部分设置为公司属性。

我在搜索时确实设置了谓词:

NSPredicate *predicate =[NSPredicate predicateWithFormat:@"firstName contains[cd] %@", searchBar.text];

我得到错误:
NSFetchedResultsController ERROR: The fetched object at index 3 has an out of order section name 'company2. Objects must be sorted by section name'

当我有 sortDescriptor 时:
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES selector:@selector(caseInsensitiveCompare:)]; 

我确实注意到当我将其更改为
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName"` ascending:YES selector:@selector(caseInsensitiveCompare:)];

现在搜索工作正常,没有错误。 initWithKey 参数是否必须与谓词中的属性名称匹配?我不明白。

最佳答案

来自 NSFetchedResultsController 文档:

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.



在您的情况下,您需要使用两种排序(在数组中)。第一个元素应该是公司名称属性的排序,第二个元素应该是 lastName/firstName 属性的排序。

关于ios4 - NSFetchedResultsController 错误 : The fetched object at index X has an out of order section name Y. 对象必须按部分名称排序',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6267398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com