Core-Data iPhone: could not locate an NSManagedObjectModel

后端 未结 4 1474
执念已碎
执念已碎 2020-11-29 23:53

I am using Apple\'s CoreDataBooks sample project as a learning aid for core data.

I modified the app so that when the app loads I show a menu page first - not the B

4条回答
  •  长情又很酷
    2020-11-30 00:38

    Ok.

    Placing the following code inside of the RootViewController's viewDidLoad eliminates the error:

    if (managedObjectContext == nil) 
    { 
        managedObjectContext = [(CoreDataBooksAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
        NSLog(@"After managedObjectContext: %@",  managedObjectContext);
    }
    

    I found someone with a similar problem here on SO: link text

    As Aryeh pointed out in that post: "In short you are trying to fetch an entity from an objectContext that hadn't been set up yet. Your options therefore are to set it up right then or do elsewhere in the app before this view loads."

提交回复
热议问题