gpt4 book ai didi

cocoa-touch - 在索引 501 处获取的对象有一个乱序的部分名称 'JOURNAL OF APPLIED PHYSICS. Objects must be sorted by section name'

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:27:39 25 4
gpt4 key购买 nike

我有一个包含期刊章节名称的文章数据库。一篇是《Journal of Applied Physics》,一篇是《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];

最佳答案

我的直觉告诉我,而不是:

[fetchRequest setSortDescriptors:[self getSortDescriptor]];

你应该写:

[fetchRequest setSortDescriptors:sortDescriptors];

关于cocoa-touch - 在索引 501 处获取的对象有一个乱序的部分名称 'JOURNAL OF APPLIED PHYSICS. Objects must be sorted by section name',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6180317/

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