How to replace a navigation root controller by tab

2019-07-25 18:28发布

问题:

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?

回答1:

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



回答2:

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