【问题标题】:The fetched object at index [i] has an out of order section name 'å在索引 [i] 处获取的对象有一个乱序的部分名称 'å
【发布时间】:2013-08-14 18:51:12
【问题描述】:
Error fetching: Error Domain=NSCocoaErrorDomain Code=134060 

"The operation couldn’t be completed. (Cocoa error 134060.)" 
UserInfo=0x132eb960 {reason=The fetched object at index 76 
has an out of order section name 'å. Objects must be sorted by section name'}

我查了一下,还有其他同名的问题,但是在这种情况下,问题是由于变音字母符号而出现的。

- (NSFetchedResultsController *)fetchedResultsControllerWithPredicate:
(NSPredicate *)aPredicate {
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];

    fetchRequest.entity = [Word MR_entityDescription];

    [fetchRequest setFetchBatchSize:20];
    [fetchRequest setPredicate:aPredicate];

    NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name"
                                                                     ascending:YES
                                                                      selector:@selector(localizedCompare:)];

    fetchRequest.sortDescriptors = @[sortDescriptor];

    NSFetchedResultsController *aFetchedResultsController =
    [[NSFetchedResultsController alloc]
     initWithFetchRequest:fetchRequest
     managedObjectContext:localContext
     sectionNameKeyPath:@"name.stringGroupByFirstInitial" cacheName:nil];

    aFetchedResultsController.delegate = self;

    NSError *anyError = nil;
    if (![aFetchedResultsController performFetch:&anyError]) {
        NSLog(@"Error fetching: %@", anyError);
    }

    return aFetchedResultsController;
}

如果我将localizedCompare: 替换为compare:,则不会出现提取错误, 但是有些索引的顺序错误,并且没有显示部分。

【问题讨论】:

  • 它们按什么顺序排列?我希望localizedCompare: 是正确的答案。
  • @TomHarrington 'localizedCompare:' 为获取请求提供了一条错误消息(我在帖子开头写了它)。
  • localizedCompare:返回的结果与使用其自己的本地化比较实现的 SQLite 支持的持久存储的获取请求返回的结果不同。当涉及到“不寻常”的角色时,这一点尤其明显。字符“Æ”是另一个给系统带来麻烦的字符,许多冰岛语和斯堪的纳维亚语字符也是如此。两年来我一直在努力解决这个问题,但无济于事。我希望你能得到解决方案。
  • @MartinR 所以,如果我理解正确,localizedCompare: 只有在 sectionNameKeyPath 为 nil 时才有效?
  • @Shmidt:我已经删除了我的评论,因为我不确定了。也许 gschandler 给出了正确的理由。

标签: objective-c core-data ios6 nsfetchedresultscontroller


【解决方案1】:

不幸的是,这本身并不是一个解决方案......

localizedCompare: 不会返回与使用其自己的本地化比较实现从获取请求返回到 SQLite 支持的持久存储的结果相同的结果。当涉及到“不寻常”的角色时,这一点尤其明显。

字符 Æ 是另一个给系统带来麻烦的字符,许多冰岛语和斯堪的纳维亚语字符也是如此。两年来我一直在努力解决这个问题,但无济于事。

否则,只要您不存在这些“不寻常”字符,它就会很好地工作。我的解决方法是检测错误,将sectionNameKeyPath 设置为nil,然后强制重新获取。不理想,也不高效,但总比用户什么都看不到。

【讨论】:

    猜你喜欢
    • 2012-08-22
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    相关资源
    最近更新 更多