核心数据和TabViewController
在我的项目中,我使用 tabBarController,然后在我的选项卡之一上添加一个导航控制器。
我遇到的问题是这样的:如果我在 AppDelegate 中使用此代码:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 应用程序启动后覆盖自定义点
[窗口addSubview:[rootController视图]];
[窗口makeKeyAndVisible];
返回是; } 我的 tabBar 视图(位于 main.xib 中)出现,但是当我单击导航控制器的选项卡(正在使用核心数据)时,应用程序崩溃并出现此错误:
NSInternalInconsistencyException',原因:'+entityForName:可以找不到实体名称“HotSprings”的 NSManagedObjectModel
因此,我找到了 AppDelegate 的以下代码: - (void)applicationDidFinishLaunching:(UIApplication *)application {
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
// Handle the error.
}
RootViewController *rootViewController = (RootViewController *)[navController topViewController];
rootViewController.managedObjectContext = self.managedObjectContext;
[window addSubview:[navController view]];
[window makeKeyAndVisible];
} 但是,当然,它会加载导航控制器视图并忽略 main.xib 和选项卡栏控制器。
所以,我需要知道如何使用最后一个代码,但加载选项卡栏和 main.xib。我尝试将 navController 更改为我的 rootController (这是我的 tabBarController 属性,但它不喜欢与导航控制器关联的“topViewController”。
谢谢,Jaime
In my project I'm using a tabBarController, then on one of my tabs, I add a navigation controller.
The problem I'm having is this: If I use this code in the AppDelegate:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch
[window addSubview:[rootController view]];
[window makeKeyAndVisible];
return YES;
}
my tabBar view (which is in the main.xib) comes up, but when I click on the tab for the navigation controller (which is using core data) the app crashes with this error:
NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'HotSprings
So, I found this code for the AppDelegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
// Handle the error.
}
RootViewController *rootViewController = (RootViewController *)[navController topViewController];
rootViewController.managedObjectContext = self.managedObjectContext;
[window addSubview:[navController view]];
[window makeKeyAndVisible];
}
But, of course, it loads the navigation controller view and ignores main.xib and the tab bar controller.
So, I need to know how to use this last code, but load the tab bar and main.xib. I tried changing the navController to my rootController (which is my tabBarController property, but it doesn't like the "topViewController", which is associated with the navigation controller.
Thanks, Jaime
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更仔细地阅读错误消息。错误出现在您的核心数据实体名称中,而不是在您的视图控制器中
You need to read the error message more carefully. The error is in your core data entity name, not in your view controller