7

我不断从 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 并没有帮助。

任何关于从哪里开始寻找解决方案的想法将不胜感激!

4

2 回答 2

16

看起来您正在释放 aUIViewController而不是释放其关联的NSFetchedResultsController. NSFetchedResultsController正在尝试通知其代表(很可能是您的)UIViewController退出时保存。

于 2010-08-20T16:59:37.753 回答
5

要详细说明 Marcus 的回答,您需要确保在视图消失时为您的 NSFetchedResultsController 取消委托:

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

    self.fetchedResultsController.delegate = nil;
}
于 2013-02-16T23:31:53.157 回答