Tutorial :Adding UITabBar



Question:

I have a UINavigationBar based application - only a one navigation bar that is handling all the work with views in my app.

And I want to have a tab bar at a bottom part of every view that will take the user to whatever view he would like to go.

What is the easiest way to add a tab bar to an application?

Thank you in advance, Ilya.


Solution:1

Be sure to add the tabBar ABOVE your navigation bar in your view hierarchy. Depending on the structure of your user flow, you may end up with multiple navigationControllers.

                           tabBarController (w/ 3 sections, in this example)                                  |                    ------------------------------                    |             |               |              navController1 navController2 navController3  

Each navController maintains it's own stack.


Solution:2

If you want to have a tab bar that is the same for all your views and is always visible, then you have to:

  1. In your application delegate class, add an IBOutlet for the new UITabBarController named e.g. tabBarController
  2. In your mainwindow.xib file, you have to add a tab bar view controller, interface builder will automatically create the tab bar for you
  3. In interface builder, configure the tab bar settings, and the tabs, you may nest your UINavigationController in the tab bar.
  4. bind the UITabBarController instance to the IBOutlet you created at step 1
  5. change your applicationDidFinihedLaunching method to look like the following code.

    • (void)applicationDidFinishLaunching:(UIApplication *)application { [window addSubview:tabBarController.view]; }

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »