在我的项目中,我使用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 *)应用程序方法替换为CoreDataReceipeis示例代码
- (void)applicationDidFinishLaunching:(UIApplication *)application {
todoRootController.managedObjectContext = self.managedObjectContext;
//////////////// same stuff
}
然后它给出'NSInternalInconsistencyException',原因是:'+ entityForName:无法找到实体名称的NSManagedObjectModel'任务''
答案 0 :(得分:0)
利用Interface Builder设置键入选项卡时将显示的选项卡视图控制器。
如果您必须以编程方式执行此操作,那么您应该查看TabBarControllers的文档。
的
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init];
MyViewController* vc1 = [[MyViewController alloc] init];
MyOtherViewController* vc2 = [[MyOtherViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
tabBarController.viewControllers = controllers;
// Add the tab bar controller's current view as a subview of the window
[window addSubview:tabBarController.view];
}