当排序的属性不完全相同时,NSFetchedResultsController无法执行 [英] NSFetchedResultsController can't performFetch when sorted attributes aren't all the same

查看:139
本文介绍了当排序的属性不完全相同时,NSFetchedResultsController无法执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题, NSFetchedResultsController 只能处理 performFetch 所有 entity.number s是相同的数字(此 NSFetchedResultsController 使用 number 对实体进行排序。这有点像播放列表,它使用 indexNumber 属性来保持播放列表顺序。

I have a strange issue with an NSFetchedResultsController that can only handle performFetch when all the entity.numbers are the same number (this NSFetchedResultsController sorts the entities using number. This is kind of like a playlist that uses an indexNumber attribute to keep the playlist order.

- (IBAction)addSetPressed {
    int theNumber = [self.nameTextField.text intValue];
    WSet *set = [WSet wSetWithNumber:theNumber inManagedObjectContext:self.workout.managedObjectContext];
    [self.workout addExercisesObject:set];
}

self.nameTextField 在我的 UITableView 的标题中。我会在那里放一个数字,比如 1 例如,然后我按 UIButton 调用 addSetPressed 。这段代码是指将实体添加到我的模型和 NSFetchedResultsContro ller 检测模型中的更改并更新我的 UITableView

self.nameTextField is in my UITableView's Header. I'll put a number there, like 1 for example, and then I press a UIButton that calls addSetPressed. This code is meant to add an entity to my model and the NSFetchedResultsController detects the change in the model and updates my UITableView.

这是问题:
当我在 self.nameTextField 中输入 1 (或任何数字)时,我可以按 UIButton 我想要多次,代码效果很好。但当我更改 self.nameTextField 中的数字时,我收到一个错误:

Here's the issue: When I enter 1 (or any number) in self.nameTextField, I can press the UIButton as many times as I want to and the code works great. But when I change the number in self.nameTextField I get an error:

[__NSCFNumber localizedCaseInsensitiveCompare:]: unrecognized selector sent to instance 0xb665b80
CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.

我花了最近12个小时搞乱我的代码并研究问题,但我可以'弄明白。

I have spent the last 12 hours messing around with my code and researching the issue, but I can't figure it out.

如果你和我一起提示,或者可以指出一些可以提供帮助的文献,我会很棒。

It will be great if you a and tip for me, or can point me towards some literature that can help.

推荐答案

已修复!

这是问题所在。当我设置 sortDescriptor 时,我需要选择适当的选择器来比较我正在排序的属性类型。

Here's the problem. When I setup my sortDescriptor, I need to select the appropriate selector to compare the type of attribute I'm sorting by.

这是正确的,因为号码被处理为 NSNumber

This is correct since number is handled as an NSNumber

request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"number" ascending:YES selector:@selector(compare:)]];

之前我有 NSString 的选择器。

这篇关于当排序的属性不完全相同时,NSFetchedResultsController无法执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆