In this application we are going to create it by using Window based application.
In this application we are going to create it by using Window based application.
Tab Bar Controller
In this Tutorial, you will learn to
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.
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.