在保存带有'NSInvalidArgumentException'的managedObjectContext时崩溃,但只是零星地

时间:2010-08-20 16:02:09

标签: core-data nsmanagedobjectcontext

我一直在使用managedObjectContext上的save:命令崩溃。它甚至不满足NSLog语句,所以我没有看到未解决的错误语句,所以我无法弄清楚问题可能是什么。它不是每次都会发生,而只是偶尔发生。

这是代码(基本上想要增加一个计数器):

 if ([[managedObject valueForKey:@"canSee"]boolValue]){
    int read = [[managedObject valueForKey:@"timesRead"] intValue] +1;
    [managedObject setValue:[NSNumber numberWithInt:read] forKey:@"timesRead"]; 


    NSError *error;
    if (![resultsController.managedObjectContext save:&error]) {  //<-- crashes on this line!
        NSLog(@"Unresolved Core Data Save error %@, %@", error, [error userInfo]);
        exit(-1);
    }

在控制台窗口中,我收到如下消息:

  2010-08-20 08:12:20.594 AppName[23501:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet controllerWillChangeContent:]: unrecognized selector sent to instance 0xe54f560'

或者这个:

  2010-08-20 08:12:20.594 AppName[23501:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet controllerWillChangeContent:]: unrecognized selector sent to instance 0xe54f560'

甚至是这样:

  2010-08-19 23:09:59.337 AppName[761:307] Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  -[UITableViewLabel controllerWillChangeContent:]: unrecognized selector sent to instance 0x7f0a860 with userInfo (null)
  2010-08-19 23:09:59.356 AppName[761:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewLabel controllerWillChangeContent:]: unrecognized selector sent to instance 0x7f0a860'

然后它显示第一次抛出的调用堆栈,然后是通知(在抛出'NSException'实例后调用终止,'[切换到进程23501]'和'程序接收信号:'SIGABRT“。'

我认为这个问题与CoreData有关,但我不确定。我已经清理了我的构建和目标,它似乎没有帮助。我试过锁定/解锁ManagedObjectContext但它没有帮助。

此处有关于从哪里开始寻找解决方案的任何想法都将非常感谢!

2 个答案:

答案 0 :(得分:16)

您似乎正在发布UIViewController并且未发布其关联的NSFetchedResultsControllerNSFetchedResultsController尝试在退出时通知其代理人(很可能是您的UIViewController)。

答案 1 :(得分:5)

要详细说明Marcus的回答,您需要确保在视图消失时为NSFetchedResultsController指定代理:

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    self.fetchedResultsController.delegate = nil;
}