开发者

TabBar application, CoreData related application crash

开发者 https://www.devze.com 2023-03-10 11:05 出处:网络
In my project I\'m using a tabBarController as the rootView Controller, then on one of my tabs, I add my exsisting ToDoList application.The problem I\'m having is this: If I use this code in the AppDe

In my project I'm using a tabBarController as the rootView Controller, then on one of my tabs, I add my exsisting ToDoList application. The problem I'm having is this: If I use this code in the AppDelegate: ToDoList is load as RootView. But I want it to show only after appropriate tab selected.

- (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];
}

The I replace applicationDidFinishLaunching:(UIApplication *)application method as CoreDataReceipeis sample code

- (void)applicationDidFinishLaunching:(UIApplication *)application {  
    todoRootController.managedObjectContext = self.managedObjectContext;

//////////////// same stuff
}

But then it gives 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Task''


Utilize Interface Builder to set the Tab View Controllers that will be displayed when a tab is typed.

If you must do it programmatically then you should check out the documentation for TabBarControllers.

of

- (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];

} 
0

精彩评论

暂无评论...
验证码 换一张
取 消