Search code examples
iphoneiosuitabbarcontrolleruitabbar

implementation of tab bar controller


this view present 5 buttons(sorry is in french)

this view present 5 buttons(sorry is in french)

i want to implement a tabbarcontroller when i choose one button , it will navigate to the tabbarControllerClass my problem that i don't know how to program action in every buttton to push to this view

this is an example of mesAlertbuttonpressed

-(IBAction)MesAlertsButtonPressed:(id)sender{
TabBarControllerViewController *tabBarControllerViewController = [[TabBarControllerViewController alloc]initWithNibName:@"TabBarControllerViewController" bundle:nil];
tabBarControllerViewController.TypeView=@"Alert";
[self.navigationController pushViewController:tabBarControllerViewController animated:YES];

enter image description here


Solution

  • Create method in AppDelegate.m class and call that method when you want to display tabController For Example:

    -(void)setRootViewControllerTab1{
    
        UIViewController *viewController1, *viewController2, *viewController3, *viewController4, *viewController5;
        UINavigationController *navviewController1 , *navviewController2, *navviewController3, *navviewController4, *navviewController5;
    
        viewController1 = [[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil] autorelease];
        navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
    
        viewController2 = [[[HowItWorksViewController alloc] initWithNibName:@"HowItWorksViewController" bundle:nil] autorelease];
        navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
    
        viewController3 = [[[JoiniAppointViewController alloc] initWithNibName:@"JoiniAppointViewController" bundle:nil] autorelease];
        navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
    
    
        viewController4 = [[[BecomeBussUserViewController alloc] initWithNibName:@"BecomeBussUserViewController" bundle:nil] autorelease];
        navviewController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
    
        viewController5 = [[[ContactUsViewController alloc] initWithNibName:@"ContactUsViewController" bundle:nil] autorelease];
        navviewController5=[[UINavigationController alloc]initWithRootViewController:viewController5];
    
        self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2,navviewController3,navviewController4,navviewController5, nil];
    
        self.window.rootViewController = self.tabBarController;
    
        [self.window makeKeyAndVisible];
    }
    

    and call that method on that button click event like bellow..

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate setRootViewControllerTab1];