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

烂漫一生 提交于 2019-12-11 13:03:36

问题


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


来源:https://stackoverflow.com/questions/5190040/how-to-replace-a-navigation-root-controller-by-tab-bar-controller-in-existing-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!