在 insertMethod 应用程序中使用 Core Data 会崩溃并给出 NSInternalInconsistencyException 并显示错误消息 Context已经有一个协调器
我正在 xcode 4.2 中的 insertMethod (在 MasterViewController.m 类中)实现一个核心数据示例,我的应用程序崩溃并出现 NSInternalInconsistencyException 和错误消息: Context 已经有一个协调器;无法替代。 有哪位朋友可以告诉我这个异常的含义以及
下面给出的错误消息插入方法:-
(void)insertNewObject
{
detailViewControllerObj = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
detailViewControllerObj.delegate = self;
NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] init];
self.managedObjectContext = addingContext;
[managedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
detailViewControllerObj.cust = (Customer *) [NSEntityDescription insertNewObjectForEntityForName:@"Customer" inManagedObjectContext:addingContext];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewControllerObj];
[self.navigationController presentModalViewController:navController animated:YES];
}
并且应用程序在执行后崩溃
[managedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
任何帮助都将更加值得赞赏..
i am implementing a core data example in xcode 4.2 at insertMethod (in MasterViewController.m class) my app crashes with a NSInternalInconsistencyException and error message: Context already has a coordinator; cannot replace.
can any buddy tell me the meaning of this exception and error message
insert method given below:-
(void)insertNewObject
{
detailViewControllerObj = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
detailViewControllerObj.delegate = self;
NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] init];
self.managedObjectContext = addingContext;
[managedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
detailViewControllerObj.cust = (Customer *) [NSEntityDescription insertNewObjectForEntityForName:@"Customer" inManagedObjectContext:addingContext];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewControllerObj];
[self.navigationController presentModalViewController:navController animated:YES];
}
and the app crashes after exectution of
[managedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
Any help will be more appreciable..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这意味着在 ManagedObjectContext 初始化时,您已经将其与存储绑定了。因此,您不需要在此处再次绑定它,因此如果您从代码中删除这一行,您的代码将正常工作,因为您尝试执行的步骤已经在先前的某个阶段完成。
this means that at the time of managedObjectContext's initialization, you have already binded it with the store. so you dont need to bind it again here so if you remove this line from your code, your code will work fine as the step you are trying to do has already been done at some prior stage.