简体   繁体   中英

add tabs to existing project

I have a running project with 2 xibs for 2 UIViewControllers (no storyboard). I am looking for the shortest way to add tabs at the bottom of the screen being able to switch between the views via the tabs.

Thanks,

Simon

SHORT ANSWER:

  1. In your MainWindow add a UITabBarController
  2. In your UITabBarController add UITabBarItem s for a UINavigationController
  3. For each of those UINavigationController s set the RootViewController to be the UIViewController s that you have already

EDIT: More detailed steps, but not necessarily perfect:

  1. Find out which view is loaded when your app is loaded (depending on your XCode, this may well be MainWindow.xib or its RootViewController )
  2. Edit the thing from #1 (if defined in code, edit in code; if designed through XIB, edit through XIB) so that it is pointing to a UITabBarController (ie mainWindow.rootViewController = tabBarController in code)
  3. Foreach view controller you want to add, add a UINavigationController . If you are using XIB, then just drag new navigation controllers to the tab bar. If you are using code, use tabBarController.viewControllers = @[navController1,navController2,navController3,...]
  4. Foreach of the nav controllers you just created, set its rootViewController to be your ViewController you want to add.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM