Ashu
Ashu

Reputation: 11

How to replace a navigation root controller by tab bar controller in existing iphone app

I have an existing iphone app whihc has nav controller as its root controller. Now i have to add a tab bar controller at the bottom of the screen. how can i achieve this change?

Upvotes: 1

Views: 907

Answers (2)

Vaibhav Tekam
Vaibhav Tekam

Reputation: 2344

Are you having more than one viewControllers to be shown in the tab? Add the viewControllers to tabBar's viewControllers. USe this property

tabBarController.viewControllers = view_Controllers_Array;

eg.

NSMutableArray * viewControllers = [[NSMutableArray alloc]init];


FirstViewController * firstViewController = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
[viewControllers addObject:nvc];
[nvc release];

SecondViewController * secondViewController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
 nvc = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
[viewControllers addObject:nvc];
[nvc release];

UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = viewControllers;
[window addSubview:tabBarController.view];

Upvotes: 1

Kshitiz Ghimire
Kshitiz Ghimire

Reputation: 1716

first you need to create tab bar controller in the root , then you put navigation controller or other view controller for each tab bar

good luck

Upvotes: 1

Related Questions