This is part of an ELC Tech Network

UITabBar iPhone Tutorial



[ Javascript required to view QuickTime movie, please turn it on and refresh this page ]

This tutorial will show you the basics of using the UITabBar and UITabBarItem controls when programming for the iPhone.

I will be showing you step by step in the video how to create a project from a UITabBar template and add additional UITabBarItems as well as additonal views to be displayed with these items.  Here is a brief explanation of each step:

1. Create a new project from a UITabBar template

This is pretty straight forward.  We will be using Apple’s default UITabBar template to start our project.  This is a fully functioning app.  You can click Build and Go to see it run.

2. Open Interface Builder (click on mainWindow.xib) and Add addtional UITabBar items

To add additonal UITabBarItems, you simply drag them from the library on to the UITabBar.  For each new item, you must specify the name of the view that will be shown when the item is clicked.  This is done by clicking on the tab bar item and clicking Tools -> attributes inspector.  There should be a box titled “Nib Name”.  Whatever you enter here will be the name of the view that will be loaded when this tab is clicked.

So for this tutorial, we entered ThirdView.  So, naturally when we created our view to be loaded here, we saved it as “ThirdView.xib”.  This is one Gotcha when working with these components.

3. Changing the text of the UITabBarItems

This is took me a while to figure out.  To change the text, image, or style of the UITabBarItem, double click on it.  You should now be able to access these settings in the Attributes Inspector.

4. Set the Background Color For Views 1 and 2

This was pretty easy.  For the first view, we simply clicked on it and clicked the box next to “Background” in the Attributes Inspector.  Next, we did the same to the secondView by opening up SecondView.xib in Interface Builder.

5. Create ThirdView

We need to create the third view to be loaded when the user clicks on the UITabBarItem that we inserted.  This was done inside of Interface Builder by clicking File -> new and selecting View. The next thing we did was drag a label from the library and add it to the view.  Finally, we set the background color like we did in the other views.

Advertisement

Be sure when you save this view, you name it ThirdView.xib (this corrisponds the name that we put in the “Nib Name” box in step 2).  Also, be sure to save this view in your projects folder (sometimes Interface Builder does not navigate here by default).

6. Connecting ThirdView to the ViewController

In this step we connect the ThirdView to our FirstViewController.  Notice that all of the views get connected to this view controller.  This will handle all of the UI components put on to each view. *Note: this step can’t be done until ThirdView is saved and added to the project.

So to connect this view to FirstViewController, simply click on the File’s Owner object and select FirstViewController from the drop-down in the Identity Inspector.

The last thing we need to do is connect the view.  So control-click from File’s Owner and drag the line to the View object. The word “View” should pop up.  Click on it and the views are now connected.

That should be it! Click Build and Go and you are done.

Well, I hope you guys have enjoyed the video tutorial.  I know that the audio is kind of low.  This is because I used my computer’s built in microphone and it’s not the greatest.  I have since purchased a new microphone (thanks again to all who have donated thus far) and future tutorials will have much better audio quality.  I would LOVE to hear your feedback on the videos.  I’m a total noob when it comes to screencasts and would love your constructive criticism.  Thank you all and Happy iCoding!

Download  the source code for this tutorial here

This entry was posted in Interface Builder, iPhone Programming Tutorials and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

63 Comments

  1. Posted June 8, 2009 at 9:04 am | Permalink

    Thank you for posting this excellent tutorial. I was always confused regarding the tab bar but this made it much more clearer.

    Thanks again! :)

  2. mamatha
    Posted June 17, 2009 at 4:36 am | Permalink

    its a great tutorial
    thanks alot..

  3. Posted June 19, 2009 at 3:57 pm | Permalink

    Great screencast Brandon. Thanks!

    BTW, what’s the recorder you used? Thanks again :-)

  4. Posted July 21, 2009 at 1:21 pm | Permalink

    good tutorial.
    I wish to recreate the top tabs that Facebook has it.
    I saw inside the .ipa and they are buttons.
    Where do I find a tutorial how to reproduce this effect?

  5. James
    Posted September 7, 2009 at 10:24 am | Permalink

    Hey Could you please show us how you use the controller with these views? I’ve tried connecting the labels to my firstviewcontroller and it just doesnt run :(

  6. Posted September 14, 2009 at 5:26 am | Permalink

    Hi

    This is nice tute but i was wondering if u could have provided some more function of tab bar like displayinh images on tab bar items…

  7. Posted September 17, 2009 at 12:00 am | Permalink

    I have a simple question (newbie obviously)

    I decided to play with this app a little and add a fourth item (a search page). The UI loads properly, and selecting the tab bar icon shows the page, but if I type something in the search field, I can never get the keyboard to go away (and it covers the tabview so I’m stuck there)

    What have I missed?

    Thanks in advance.

  8. Posted September 21, 2009 at 1:17 pm | Permalink
    • me mine
      Posted May 19, 2010 at 3:27 pm | Permalink

      You Qoran fricks you hate what is human and beautiful. You are out there to destroy the world because you have never produced anything good to serve humanity.

  9. mora
    Posted September 21, 2009 at 2:00 pm | Permalink
  10. Posted December 4, 2009 at 1:58 pm | Permalink

    Hey man!

    Great tutorial, I totally understand it now. However, you went a little quick through it, so I had to rewind a couple of times…

    Robin Kanters
    the Netherlands

  11. Posted April 9, 2010 at 3:03 pm | Permalink

    I am working on a recipe app at this time…
    My question is:
    The app is navigational. After navigating to the right recipe, the recipe appears on a uitext view. What iI want to do is to implement a button which will add the recipe to a “favorites” tab.
    Is there a specific function to help me accomplish that?
    Any help would be appreciated.

  12. Posted August 7, 2010 at 11:00 pm | Permalink

    Thank you so much – I am looking for easy-2-use tutorials and you hit the nail right on the head.

    Thank you again!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">