使用Core Data和insertMethod应用程序崩溃,并给出NSInternalInconsistencyException与错误消息上下文已经有协调器 [英] Using Core Data and in insertMethod App crashes and give NSInternalInconsistencyException with error message Context already has a coordinator

查看:116
本文介绍了使用Core Data和insertMethod应用程序崩溃,并给出NSInternalInconsistencyException与错误消息上下文已经有协调器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序崩溃与一个 NSInternalInconsistencyException和错误消息:上下文已经有一个协调器;不能替换。
可以让任何好友告诉我这个异常和错误消息的意义



插入方法如下: -

 (void)insertNewObject 
{
detailViewControllerObj = [[DetailViewController alloc] initWithNibName:@DetailViewControllerbundle:nil];
detailViewControllerObj.delegate = self;
NSManagedObjectContext * addingContext = [[NSManagedObjectContext alloc] init];
self.managedObjectContext = addingContext;

[managedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];

detailViewControllerObj.cust =(Customer *)[NSEntityDescription insertNewObjectForEntityForName:@CustomerinManagedObjectContext:addingContext];

UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:detailViewControllerObj];

[self.navigationController presentModalViewController:navController animated:YES];

}



应用程式崩溃后

  [managedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator] 

任何帮助将更加明显。

解决方案

这意味着在managedObjectContext初始化时,您已经将其绑定到存储。所以你不需要在这里重新绑定它,所以如果你从代码中删除这行,你的代码将正常工作,因为你尝试做的步骤已经在一些前期阶段。


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..

解决方案

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.

这篇关于使用Core Data和insertMethod应用程序崩溃,并给出NSInternalInconsistencyException与错误消息上下文已经有协调器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆