1

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''

Eimantas
  • 48,927
  • 17
  • 132
  • 168
smartsanja
  • 4,413
  • 9
  • 58
  • 106
  • By default the first tab is displayed when the Tab Controller is called. Do you want the view controller for the first tab to display only when it is touched ? – Legolas Jun 03 '11 at 17:46

1 Answers1

0

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

} 
bdparrish
  • 3,216
  • 3
  • 37
  • 58
  • I have set my ToDoListViewController to appropriate tab, in interface builder. But as I mentioned, If I use 1st code segment, ToDoListViewController load as rootview. If I use 2nd code segment, it gives above mentioned exception. I'm really fedup with this :( :( – smartsanja Jun 05 '11 at 04:20