Home Tutorial Iphone Examples Tab Bar Controller

 
 

Share on Google+Share on Google+
Tab Bar Controller
Posted on: August 25, 2009 at 12:00 AM
Advertisement
In this application we are going to create it by using Window based application.

Tab Bar Controller

In this Tutorial, you will learn to

      a)  Create a Tab Bar Controller

      b)  Adding view and

      c)  Adding the Tab Bar Controller to the window.

In this application we are going to create it by using Window based application.

So we will find one window.

There is  .h and  .m file.

We are going to add tab bar to Window.    

Creating a Tab Bar Controller:

Create a new project by selecting Window-Based Application.Open the Interface Builder by double clicking the MainWindow.xib file and add a Tab Bar Controller from the library. It consist of two Bar Items.

A Tab Bar Items acts as a button by which we can change to another view by clicking the Tab Bar Items.We can change the title and the image by double clicking on the Tab Bar Item Button.

Adding View:

Drag and drop the View from library to the place holder where it says View (above Tab Bar Items). We can add Any no of view(as our requirement) by Clicking View and the Tab Bar Items (we can add number of buttons on Tab Bar Controller this can be done by clicking on Tab Bar Controller and then select in Tools -> attribute Inspector and then in view Controller add as many view required by clicking the + button).

Adding Tab Bar Controller to the Window:

Now we have to add Tab Bar Controller to Window. To do this, we need to create a connection, open Interface builder and in it right click on Tab Bar Controller App Delegate and then connect Tab Bar Controller to the Variable (tabBarController) . Before connecting we have to create an instance variable of type UITabBarController and mark it with IBOutlet  in .h file so it shows up in the Interface Builder.

.h file will look like:

#import <UIKit/UIKit.h>

@interface TabBarAppDelegate : NSObject <UIApplicationDelegate>

{

    UIWindow *window;

    IBOutlet UITabBarController *tabBarController;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

In this we are Declaring Tab Bar Controller as IBOutlet and also the property of it.

Make connection in interface builder as below

 

.m file will look like this:

#import "TabBarAppDelegate.h"

@implementation TabBarAppDelegate

@synthesize window, tabBarController;

- (void)applicationDidFinishLaunching:(UIApplication *)application

 {   

    // Override point for customization after application launch

    [window makeKeyAndVisible];

    [window addSubview:[tabBarController view]];

}

 - (void)dealloc

 {

    [window release];

    [tabBarController release];

    [super dealloc];

}

@end

In this we are synthesizing tabBarController, and also adding it to window by using [window addSubview:[tabBarController view]] and finaly releasing it.

Press  Build And Go Button.  

Download code from here.

 

Advertisement

Related Tags for Tab Bar Controller :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 25, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com