How to add an UITabBarController with UINavigationController
You won't use the Interface Builder but want an UITabBarController with an UINavigationController? All is possible... I've used several times an programmatically added UINavigationController inside an UITabBarController.
In this tutorial you would learn to add an UINavigationController programmatically to an UITabBarController.
To add an UINavigationController programmatically open your 'AppDelegate.m'. Change the method application: didFinishLaunchingWithOptions: with the code below to create an UITabBarController with an UINavigationController programmatically.
// Create instance of UINavigationController
UINavigationController *myNavigationController;
// Create initialized instance of UITabBarController
UITabBarController *tabBarController = [[UITabBarController alloc] init];
// Create initialized instance of NSMutableArray to hold our UINavigationControllers
NSMutableArray *tabs = [[NSMutableArray alloc] init];
// Create first UIViewController
UIViewController *myFirstViewController = [[UIViewController alloc] init];
[myFirstViewController setTitle:@"First"];
// Initialize the UINavigationController
myNavigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController];
// Add UINavigationController to you tabs
[tabs addObject:myNavigationController];
// Release UIViewController and UINavigationController
[myFirstViewController release], [myNavigationController release];
// Create second UIViewController
UIViewController *mySecondViewController = [[UIViewController alloc] init];
[mySecondViewController setTitle:@"Second"];
// Initialize the UINavigationController
myNavigationController = [[UINavigationController alloc] initWithRootViewController:mySecondViewController];
// Add UINavigationController to you tabs
[tabs addObject:myNavigationController];
// Release UIViewController and UINavigationController
[mySecondViewController release], [myNavigationController release];
// Add the tabs to the UITabBarController
[tabBarController setViewControllers:tabs];
// Add the view of the UITabBarController to the window
[self.window addSubview:tabBarController.view];You're ready to run your project! Now you've added programmatically an UINavigationController on an UITabBarController.
