在 insertMethod 应用程序中使用 Core Data 会崩溃并给出 NSInternalInconsistencyException 并显示错误消息 Context已经有一个协调器

发布于 2025-01-04 19:11:30 字数 1273 浏览 2 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把时间冻结 2025-01-11 19:11:30

这意味着在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文