Saturday, May 22, 2010

Creating application with UITabBarController

The diagram shows the layout of a typical IPhone application. Each UI component name is also stated in the diagram. Usually an IPhone application has one UITabBarController. When the tab bar is selected, a specific NavigationController is activated. Each Navigation Controller can be pushed with one or more View Controller. Typically other View Controller can be invoked by linking a button to the method that pop the view controller.


The hierarchy of the UI component is shown in the diagram below:
Nesting Navigation Controllers in UITabBarController
  • Create UITabBarController
                tabBarController =  [[UITabBarController alloc] init];     
  • Create each UINavigationController
               UINavigationController *navController1 = [[UINavigationController alloc] init];
               [navController pushViewController: firstViewController animated: NO];
               // .....  create other UINavigationController
  • Add all the UINavigationController / UIViewController to UITabBarController
              tabBarController.viewControllers = [NSArray arrayWithObjects:
                                                                      nil ];
             [window addSubView:tabBarController.view];
The above code is typically add to applicationDelegate viewDidFinishLaunchingWithOptions method.

Customizing the UI controller

The Title on the UINavigationController can be customized by changing the viewController.title field in the viewDidLoad method in the view class. Eg:

                      firstView.title = @"First View";  
  • The TabBarItem image and title can be customized by changing the tabBarItem field in navigationController or viewController. Eg: The customization code can be added to the viewDidLoad method of the viewController.
                        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Playlists"                                                            image: [UIImage imageNamed:@"music.png"]
                                                               tag: 0];
                        self.tabBarItem = item;
                        [item release];
  • System item can also be added to the tab bar, Eg:
                  UITabBarItem *item = [[UITabBarItem alloc] initWithTabBarSystemItemItem:    
                                                        UITabBarSystemItemContacts tag:0];                 
                  navigationController.tabBarItem = item;
                  [item release];


1 comment:

  1. Nice and very helpful information i have got from your post. Even your whole blog is full of interesting information which is the great sign of a great blogger.

    Lenovo - IdeaPad 15.6" Laptop - 6GB Memory - 1TB Hard Drive - Dark Chocolate

    Lenovo - 14" Notebook - 4 GB Memory - 320 GB Hard Drive - Black