在我的项目中,我使用 tabBarController 作为 rootView 控制器,然后在我的一个选项卡上,添加我现有的 ToDoList 应用程序。我遇到的问题是:如果我在 AppDelegate 中使用此代码:ToDoList 加载为 RootView。但我希望它仅在选择适当的选项卡后显示。
- (void)applicationDidFinishLaunching:(UIApplication *)application {
//todoRootController.managedObjectContext = self.managedObjectContext;
ToDoRootViewController *todoRootViewController = [[ToDoRootViewController alloc]initWithNibName:@"ToDoRootViewController" bundle:nil];
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
// Handle the error.
}
// Pass the managed object context to the view controller.
todoRootViewController.managedObjectContext = context;
UINavigationController *aNavigationController = [[UINavigationController alloc]
initWithRootViewController:todoRootViewController];
self.navigationController = aNavigationController;
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
[todoRootViewController release];
[aNavigationController release];
}
我将 applicationDidFinishLaunching:(UIApplication *)application 方法替换为 CoreDataReceipeis 示例代码
- (void)applicationDidFinishLaunching:(UIApplication *)application {
todoRootController.managedObjectContext = self.managedObjectContext;
//////////////// same stuff
}
但随后它给出了“NSInternalInconsistencyException”,原因:“+entityForName:找不到实体名称“任务”的 NSManagedObjectModel