Just like Navigation controller, Tab bar controller is also one of the most common parts of iPhone applications. As the name suggests, Tab bar controller controls the tabs within an application and provides a simple and easy access to other views of the same application. UITabBarController is the main class that handles the functionality of tab bar controller.

Tab bar controller provides a simple menu type way of accessing different view controllers. Default position of the tab bar controller is at the bottom of the screen.  Following figure shows the tab bar controller example. Each view controller comes with a tab bar item for customizing. Each UITabBarItem has a title and image to set that is displayed.

Setting Up a Tab Bar Controller

- (void)applicationDidFinishLaunching
// Create a tab bar controller
tabBarController = [[UITabBarController alloc] init];
// Set the array of view controllers
tabBarController.viewControllers = myViewControllers;
// Add the tab bar controller’s view to the window
[window addSubview:tabBarController.view];

Creating Tab Bar Items

Consider that we want to create a tab bar item with title “Playlists” and an image icon for music that is named “music.png”.  Following code does the trick:

- (void)viewDidLoad
UITabBarItem *item = [[UITabBarItem alloc]
image:[UIImage imageNamed:@“music.png”]
self.tabBarItem = item;
[item release];

System item

We can also create a Tab bar of system item. In this case we do not need the image or title. Suppose we want to use a Tab bar system item of “Bookmarks”. Then following code does the trick:

- (void)viewDidLoad
UITabBarItem *item = [[UITabBarItem alloc]
self.tabBarItem = item;
[item release];

More View Controllers

What happens when a tab bar controller has too many view controllers to display at once?

“More”tab bar item displayed automatically as shown in the picture below. User can navigate to remaining view controllers and can customize the order of tab bars.

Combining Tab Bar and Navigation Controllers

Create a tab bar controller

tabBarController = [[UITabBarController alloc] init];

Create each navigation controller

navController = [[UINavigationController alloc] init];
[navController pushViewController:firstViewController animated:NO];

Add them to the tab bar controller 

tabBarController.viewControllers = [NSArray arrayWithObjects:



Tagged with: C/C++ languageiPhone

Leave a Reply

Your email address will not be published.

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>


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.