Search code examples
iphoneobjective-cxcodeios5programmatically-created

how to add a tab Bar to a Default view and communicate with other views using navigation controller


It might be simple but not able to find exact solution for this.i am using xcode 4.2.

I want to use Tab bar in one of the view in my application. i went through many tutorials all tutorials are related to navigation based application and other view based application.Even i understood how to add a tab bar controller in story board which is main view.

What i need is i have class called Homepage.h and .m and .xib which is subclass of UIViewController class.Again my class is not main class its added later for one of the view.So i want to add a tab bar and communicate with navigationBar and other views so how can i do it plz give me some samples.

Problem is i want to add Tab bar to the default UIView and communicate with navigation controller and other views. i dont want to drag Tab bar controller from utilities.Incase if i drag how can i make it view on moving from one view to another as i already have a Default UIview.Please give me links or any tutorials where i can add tab bar and switch between views using navigation controller.

NOTE: i am using Single View based Application


Solution

  • Take UINavigationController object and UITabBarController object in AppDelegate.h

    In AppDelegate.h

       First *first;
       Second *second;
       Third *third;
    
    UINavigationController *navController;
    
        UITabBarController *tabbar;
    

    @property (nonatomic, retain) UITabBarController *tabbar;

    @property (nonatomic, retain) UINavigationController *navController;

    IN AppDelegate.m

    @synthesize tabbar,navController;

    in ApplicationdidFinishLaunching

    tabbar=[[UITabBarController alloc]init];

    first=[[First alloc]initWithNibName:@"First" bundle:nil];
    second=[[Second alloc]initWithNibName:@"Second" bundle:nil];
    third=[[Third alloc]initWithNibName:@"Third" bundle:nil];
    

    navController=[[UINavigationController alloc]initWithRootViewController:first];

    NSArray *viewControllerArray=[[[NSArray alloc] initWithObjects:navController1,second,third,nil] autorelease];

    [self.window addSubview:tabbar.view];
    
    [tabbar setViewControllers:viewControllerArray];
    
    [first setTitle:@"First"];
    
    [second setTitle:@"Second"];
    
    [third setTitle:@"Third"];
    

    Write this code and dont need to put Tabbar in XIB. Try thi code it will helps you.