iPhone Core Data示例生成异常 [英] iPhone Core Data Example produces exception

查看:86
本文介绍了iPhone Core Data示例生成异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不再根据NDA。

iPhone核心数据示例中有一个小结,但现在已更正。此外,示例代码总是正确的,他们只是省略了一些细节的教程。

There was an ommision in the iPhone Core Data example, but is now corrected. Also the sample code was always correct, they just left out some details in the tutorial.

(请参阅 iPhone Dev论坛以了解)

我创建了一个应用程序两次并收到相同的错误两次但在两个不同的地方):

I built an app twice and received the same error twice (but in 2 different places):


由于未捕获而终止应用程序
exception
'NSInternalInconsistencyException',
原因:'+ entityForName:can not

定位一个NSManagedObjectModel实体名称'Event''

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Event''

我阅读了苹果文档

它说明了模型缺失,或上下文为nil,或持久存储无效的问题。

It speaks to a problem with the model missing, or the context is nil, or the persistence store is not valid.

然而,由于这是我的第一个Core Data项目,我在调试中有点弱。如果需要,我可以发布代码。

However as this is my first Core Data project, I'm a little weak in debugging. I can post code if needed.

任何帮助都非常感谢。

推荐答案

我找到了答案。 (如果你想要一个iPhone 3.0 sdk版本的这个答案,请参考页面底部的链接)
这应该是在应用程序委托applicationDidFinishLaunching方法应该是这样:

I found the answer. (If you would like a iPhone 3.0 sdk version of this answer, refer to the link at the bottom of the page) This what should be in the app delegate applicationDidFinishLaunching method should be like so:

(void)applicationDidFinishLaunching:(UIApplication *)application { 

    NSManagedObjectContext *context = [self managedObjectContext];
    if (!context) {
        // Handle the error.
    }

    RootViewController *rootViewController = [[RootViewController alloc] 
                                              initWithStyle:UITableViewStylePlain]; 

    rootViewController.managedObjectContext = context;

    UINavigationController *aNavigationController = [[UINavigationController 
                                                      alloc] initWithRootViewController:rootViewController]; 
    self.navigationController = aNavigationController; 
    [window addSubview:[navigationController view]]; 
    [window makeKeyAndVisible]; 
    [rootViewController release]; 
    [aNavigationController release]; 
} 

iPhone开发论坛链接

这篇关于iPhone Core Data示例生成异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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