Tuesday, April 23, 2013

Tab Bar Application Part 1

  Tab Bar Application Part 1

Step 1

Create  a project
       


Step 2
  Add Three new Classes 
  •     FirstTabView
  •     SecondTabView
  •     ThirdTabView










Step 3

click the AppDelegate.h



add this code

//
//  AppDelegate.h
//  TabBarExample
//
//  Created by Apple on 4/24/13.
//  Copyright (c) 2013 Dhanushka Adrian. All rights reserved.
//

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) UITabBarController *tabBarController; //  add this code

@end


Step 4

click the AppDelegate.m



change the code of this method

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions




//
//  AppDelegate.m
//  TabBarExample
//
//  Created by Apple on 4/24/13.
//  Copyright (c) 2013 Dhanushka Adrian. All rights reserved.
//

#import "AppDelegate.h"

#import "ViewController.h"


#import "FirstTabView.h"
#import "SecondTabView.h"
#import "ThirdTabView.h"

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [_viewController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
   
   
    FirstTabView   *firstTab   =[[FirstTabView alloc]initWithNibName:@"FirstTabView" bundle:nil];   
    SecondTabView  *secondTab  =[[SecondTabView alloc]initWithNibName:@"SecondTabView" bundle:nil];
    ThirdTabView   *thirdTab   =[[ThirdTabView alloc]initWithNibName:@"ThirdTabView" bundle:nil];
    ViewController *fourthTab  =[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil]; 
   
    UINavigationController *nav1  =[[UINavigationController alloc] initWithRootViewController:firstTab];
    UINavigationController *nav2  =[[UINavigationController alloc] initWithRootViewController:secondTab];
    UINavigationController *nav3  =[[UINavigationController alloc] initWithRootViewController:thirdTab];
    UINavigationController *nav4  =[[UINavigationController alloc] initWithRootViewController:fourthTab];
   
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4, nil];
   
   
 
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
   
    [self.window addSubview:_tabBarController.view];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
  
}

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

}

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

}

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

}

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

}

@end





Step 5
  add a label  to  all  " .xib "  and edit that label like this.......

 ".xib " files

FirstTabView.xib
SeondTabView.xib
ThirdTabView.xib
ViewController.xib





Step 6
Run the App

   






























    






No comments:

Post a Comment