Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having a UITabBar AND a UINavigationController in an app?

Hey everyone, I am new to iPhone development and I'm not understanding the whole UINavigationController and UITabBarController idea. Is one a substitute for the other - how do apps such as Tweetie combine both?

I'd like to have my app have a persistent Tab Bar @ the bottom (which seems to be working), but also a Navigation bar at the top which can push/pop views onto the screen without removing the tab bar.

  • How can I accomplish this?
  • What should the hierarchy look like in IB as far as my MainWindow.xib with regards to all of these controllers?
  • What is best practice here?

Thanks very much,

like image 772
barfoon Avatar asked Feb 26 '10 02:02

barfoon


1 Answers

Just wrap the view controller inside the UINavigationController and Place the UINavigationController inside the UITabBar. This will work fine for you…

Example:

NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:2];

tabBarController = [[UITabBarController alloc] init];
[tabBarController setDelegate:self];

UINavigationController *navigationController = nil;
navigationController = [[UINavigationController alloc] initWithRootViewController:<Your View controller1>];
[tabBarViewControllers addObject:navigationController];
[navigationController release];
navigationController = nil;

navigationController = [[UINavigationController alloc] initWithRootViewController:<Your View controller2>];
[tabBarViewControllers addObject:navigationController];
[navigationController release];
navigationController = nil;

tabBarController = tabBarViewControllers;
[tabBarViewControllers release];
tabBarViewControllers = nil;
like image 145
Manjunath Avatar answered Sep 29 '22 21:09

Manjunath