Tuesday 29 March 2011

Tabbar Controller

In this post we will have a look at UITabBarController, there is also a class called as the UITabbar but mostly I prefer UITabBarController, TabbarController is used to control the Tabbar view and is mostly used to switch from one view to the other view.

Design Phase: In this post I am having two views one is a label view and the other is a table view, here’s how the final output will look like.



Step 1: In some of my earlier post I have explained how to show a simple label and a table so you can refer them if you like.

Step 2: For this tabbar application we will require two views so you can have the firstview as the subclass of the UIViewController which will be for the label and your second view will be the subclass of the UITableViewController which will be for the table . Make the settings for both the views by referring my earlier posts .

Step 3: Now go to the AppDelegate.m file and import both the viewControllers and create the object of both the viewControllers.

#import "TabbarDemoAppDelegate.h"
#import "firstviewController.h"
#import "secondviewController.h"

@implementation TabbarDemoAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {

// Override point for customization after application launch
firstviewController *firstVC = [[firstviewController alloc]init];
secondviewController *secondVC = [[secondviewController alloc]initWithStyle:UITableViewStylePlain];
NSArray *objectList = [[NSArray alloc]initWithObjects:firstVC,secondVC,nil];
UITabBarController *tabbarC = [[UITabBarController alloc]init];
tabbarC.viewControllers = objectList;
[window addSubview:tabbarC.view];

[window makeKeyAndVisible];
}



Code Explanation:

Now the best part about TabbarController is that it has a viewController property, which takes the array of the viewController objects.

So I have took an NSArray and added the objects of the viewController to it and ultimately using the viewController property of the UITabbarController I have supplied the data of the views that will be appearing on the tabbar

so once you have done this now you can add the tabbarController view to the window as all the information about the view is contained in the tabbarcontroller object and then press build and go to get the following output.



BitCode hopes that this post has helped you in clearing your concepts regarding the view and view controllers. You can post your queries at bitcode.pune@gmail.com for any technical assistance.

No comments:

Post a Comment