调试 NSObjectInaccessibleException 错误。对象的 ManagedObjectContext 变为零?
我有一个简单的 iPhone 应用程序,其中包含一对多礼物与收件人的关系(即,一个收件人可以收到许多礼物,但每件礼物必须发送给一个收件人。为了在礼物和收件人之间创建关系,我正在创建首先在托管对象上下文中创建一个新的收件人对象,将新的控制器的收件人对象设置为新的收件人,然后将新的控制器弹出到导航控制器上,当新的控制器返回时,我将新的收件人分配给礼物
。该交易的代码:
RecipientEditController *nextController = [
[RecipientEditController alloc]
initWithStyle:UITableViewStyleGrouped
];
Recipient *new = [NSEntityDescription
insertNewObjectForEntityForName:@"Recipient"
inManagedObjectContext:gift.managedObjectContext
];
[new addGiftsObject:gift];
nextController.recipient = new;
nextController.recipient.hideRelationships = YES;
[self.navigationController pushViewController:nextController animated:YES];
if ([new hasData]) {
gift.recipient = new;
} else {
[gift.managedObjectContext deleteObject:new];
}
break;
在新控制器中,接收者对象似乎运行正常;我可以在 ViewWillAppear 方法中打印收件人的描述,但是当我到达 tableView:cellForRowAtIndexPath 方法时,我的收件人对象不再有效:它的 ManagedObjectContextProperty 为 nil,并且调用recipient.firstName。 (在模型类和数据库中定义的属性),抛出错误。
错误:
2011-11-30 17:22:18.111 Gift Hero[36359:b603] *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x59e65c0 <x-coredata://97FDB78C-6F65-4B54-8DBB-00A9C6A4B4C8/Recipient/p21>''
知道发生了什么吗?这简直让我发疯!接收者如何在显示视图和显示表格之间无效?!
预先感谢,PT
I have a simple iphone application in with a one to many gift to recipient relationship (that is, one recipient can get many gifts, but each gift must go to one recipient. To create a relationship between a gift and a recipient, I am creating first creating a new recipient object in the managed object context, setting a new controller's recipient object to be the new recipient, and then popping the new controller onto the navigationController. When the new controller returns, I assign the new recipient to the gift.
The code for that transaction:
RecipientEditController *nextController = [
[RecipientEditController alloc]
initWithStyle:UITableViewStyleGrouped
];
Recipient *new = [NSEntityDescription
insertNewObjectForEntityForName:@"Recipient"
inManagedObjectContext:gift.managedObjectContext
];
[new addGiftsObject:gift];
nextController.recipient = new;
nextController.recipient.hideRelationships = YES;
[self.navigationController pushViewController:nextController animated:YES];
if ([new hasData]) {
gift.recipient = new;
} else {
[gift.managedObjectContext deleteObject:new];
}
break;
Within the new controller, the recipient object seems to operate normally; I can print a description of the recipient within the ViewWillAppear method. But when I get to the tableView:cellForRowAtIndexPath method, my recipient object is no longer valid: Its managedObjectContextProperty is nil, and a call to recipient.firstName (a property defined in the model class and in the database), an error is thrown.
Error:
2011-11-30 17:22:18.111 Gift Hero[36359:b603] *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x59e65c0 <x-coredata://97FDB78C-6F65-4B54-8DBB-00A9C6A4B4C8/Recipient/p21>''
Any idea what's going on? This is literally driving me nuts! How can the recipient just invalidate between displaying the view and showing the table?!
Thanks in advance, PT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以我想我已经弄清楚了。推送新的 viewController 似乎不会像调用另一个函数那样结束当前方法的执行。因此,当我在推送视图控制器后删除对象时,它会删除另一个视图控制器中的对象。我不太明白这背后的逻辑,但事实就是如此......
Ok, so I think I've figured this out. Pushing a new viewController does NOT seem to end execution of the current method, like calling another function might. So when I delete the object after pushing the view controller, it is deleting the object in the other view controller. I don't really understand the logic behind this, but it is what it is...