找不到实体名称的NSManagedObjectModel [英] could not locate an NSManagedObjectModel for entity name

查看:158
本文介绍了找不到实体名称的NSManagedObjectModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是toggleAddProject方法的代码,Core Data代码几乎与Apple的CoreDataBooks示例中的代码相同,但是当我点击添加按钮时,应用程序崩溃, entityForName:找不到NSManagedObjectModel在 newProjectController.project

This is the code for toggleAddProject method, the Core Data code is almost the same as found in Apple's CoreDataBooks sample, however when I click the add button the app crashes with entityForName: could not locate an NSManagedObjectModel for entity name 'Project' on the line starting with newProjectController.project

-(IBAction)toggleAddProject 
{
    NewProjectViewController *newProjectController = [[[NewProjectViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];

    // Create a new managed object context for the new project -- set its persistent store coordinator to the same as that from the fetched results controller's context.
    NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] init];
    self.addingManagedObjectContext = addingContext;
    [addingManagedObjectContext setPersistentStoreCoordinator:[[fetchedResultsController managedObjectContext] persistentStoreCoordinator]];
    newProjectController.project = (Project *)[NSEntityDescription insertNewObjectForEntityForName:@"Project" inManagedObjectContext:addingContext];
    [addingContext release];


    UINavigationController *addNewNavigationController = [[UINavigationController alloc] initWithRootViewController:newProjectController];
    [self.navigationController presentModalViewController:addNewNavigationController animated:YES];  
    [addNewNavigationController release];
}

一切都已合成,Project实体存在。我不知道为什么它崩溃。大多数人似乎能够通过在方法本身或viewDidLoad中插入以下代码来修复此错误:

Everything has been synthesized, the Project entity exists. I can't figure out why it crashes. Most people seem to be able to fix this error by inserting the following code either in the method itself, or in viewDidLoad:

if (managedObjectContext == nil) 
{ 
    managedObjectContext = [(CoreDataBooksAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
}

当我的应用程序代理修改时,没有什么区别。感谢您的帮助。

When modified for my app delegate it makes no difference. Thanks for any help.

推荐答案

此错误只有几个可能的来源:

This error has only a few possible sources:


  1. 在实体名称中输入。

  2. Nil管理对象上下文对象。

  3. 无法将包含实体的模型添加到上下文使用的持久存储。

  4. 无法向上下文本身添加正确的永久存储。

  1. Typo in the Entity name.
  2. Nil managed object context object.
  3. Failure to add the model containing the entity to the persistent store the context uses.
  4. Failure to add the correct persistent store to the context itself.

这篇关于找不到实体名称的NSManagedObjectModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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