NSFetchedResultsController
我遇到一个奇怪的问题,只有在performFetch
个entity.number
相同的数字时才能处理NSFetchedResultsController
(number
使用{indexNumber
对实体进行排序1}}。这有点像播放列表,它使用- (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
调用NSFetchedResultsController
。此代码用于向我的模型添加实体,UITableView
检测模型中的更改并更新我的1
。
这是问题所在:
当我在self.nameTextField
中输入UIButton
(或任意数字)时,我可以根据需要多次按self.nameTextField
,代码效果很好。但当我更改[__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.
中的数字时,我收到错误:
{{1}}
我花了最近12个小时搞乱我的代码并研究这个问题,但我无法理解。
如果你和我一起提示,或者能指出一些可以提供帮助的文献,那将会很棒。
答案 0 :(得分:3)
固定!
这是问题所在。当我设置sortDescriptor
时,我需要选择适当的选择器来比较我正在排序的属性类型。
这是正确的,因为号码被处理为NSNumber
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"number" ascending:YES selector:@selector(compare:)]];
之前我有NSString
的选择器。
答案 1 :(得分:0)
看起来NSNumber
不喜欢发送方法localizedCaseInsensitiveCompare:
。
我打算玩这个,看看我是否可以将排序值改为NSString
。
如果您有任何更好的想法,请告诉我们!