Adding Navigation/Table View/Image Picker Controller(s) Into A Tab Bar Controller

Adding a Navigation/Table View/Image Picker Controller into a UITabBarController seems to be subject of many new iPhone developers frustrations. I did have a lot of trouble figuring it out myself, but I finally did it. Here’s the correct way, fool proof I believe!

  1. To start with, add a new file, using the UIViewController template.
  2. Change the class’s type, on the new header file, from UIViewController to UINavigationController.
  3. Open a .xib file containing a UITabBarController.
  4. Select your Tab Bar Controller in the “your_xib_name.xib” window and press +1 to open the Attributes Inspector.
  5. Select Navigation/Table View/Image Picker Controller from the drop down for the correct tab.
  6. Go back to the “your_xib_name.xib” window, expand the Tab Bar Controller and select the correct tab.
  7. Press +4 to open the Identity window.
  8. Fill the class name with the navigation controller class that you created during steps 1 and 2. (if the class name doesn’t show up, you didn’t follow step 2, bad! bad! boy!).
  9. Go back to the “your_xib_name.xib” window, expand the Tab Bar Controller and also expand the correct tab.
  10. You should see a view controller in there, select it.
  11. Press +1 to open the Attributes Inspector window.
  12. Select a .nib for a view you wish to display when the navigation controller opens.
  13. Press +4 to open the Identity window.
  14. Fill the class name with the controller’s class for the .nib view¬† you selected during step 12.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

5 Responses to “Adding Navigation/Table View/Image Picker Controller(s) Into A Tab Bar Controller”

  1. Dave says:

    Or you could do it through code, like this:

    UITabBarController * t =
    [[UITabBarController alloc] init];
    MyViewController * c = [[MyViewController alloc] init];
    UINavigationController * n = [[UINavigationController alloc] initWithRootViewController:c];
    NSArray * tabs = [NSArray arrayWithObject:n];
    [n release];
    [t setViewControllers:tabs];
    [window addSubview:[t view]];


    Of course, you wouldn’t want your tabBar controller
    to be a local variable, so it would need to be an ivar of the object. This was just to illustrate how it’s MUCH easier to do this sort of thing through code.



  2. Scott says:

    Thanks! I’ve been trying to figure out how to do exactly that for
    days now.

    What’s the next step here though? Specifically, when I’m in the class (from step 14) and I want to move onto the next view, how do I access the UINavigationController that was created
    so that I can call pushViewController?

  3. alexmipego says:

    can’t remember by heart, but iirc you can use [self controller] or similar in any view controller. Check the docs.

  4. Dave says:

    Thanks for this, Alexandre. This has cleared up for me how to do this through Interface Builder. However, I still find it *much* easier to build these sorts of things through code:


  5. Diziet says:

    Just a quick note to say thank you.

Leave a Reply

For spam filtering purposes, please copy the number 4874 to the field below: