views:

57

answers:

2

I have an app that has a UITabBarController, one of the tabs of which is configured for a navigation controller.

Based on certain logic I need to attach a different root view to the navigation controller inside the tab at application launch time.

This is easily done in interface builder however, because I need to figure out what view to attach at launch time interface builder is not much use to me in this situation.

I'm guessing I will need to perform this in the applicationDidFinishLaunching method in my app delegate class by somehow getting the tab I'm interested in, and pushing the view onto it's navigation controller?

How would I go about this?

Thanks.

A: 

You're on the right track. In your app delegate's applicationDidFinishLaunching method, you need to look at whatever your condition is and pick the right thing to set as the UINavigationController's root view controller.

I'm guessing this is a login screen or something? And if you have a cached login from an earlier session you don't show it again? Is that it?

If you take a look at that method in your application delegate, you'll see where the default root view controller is getting instantiated and pushed into the nav controller. Just duplicate that code inside an if() statement. I've done this, it's straightforward.

Dan Ray
A: 

So what I did in my applicationDidFinishLaunching method was:

// get the array of tabs
NSArray *tabBarArray = tabBarController.viewControllers;
// in my case the navigation controller I'm interested in is in the 4th tab
UINavigationController *navigationController = [tabBarArray objectAtIndex:4];   

if(someLogic == true) {
    ViewController1 *viewController1 = [[viewController1 alloc] initWithNibName:@"View1" bundle:nil];
    [navigationController pushViewController:viewController1 animated:NO];
    [viewController1 release];
}
else {
    ViewController2 *viewController2 = [[viewController2 alloc] initWithNibName:@"View2" bundle:nil];
    [navigationController pushViewController:viewController2 animated:NO];
    [viewController2 release];
}

Everything working well.

KJF