YasBES
YasBES

Reputation: 2325

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

Upvotes: 1

Views: 531

Answers (3)

iEinstein
iEinstein

Reputation: 2100

Use this line of code to call a method to create tab bar-

AppDelegate *appDelegateObj = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegateObj createTabBar];

Actual Method

  -(void)createTabBar
    {
        self.tabBarController.customizableViewControllers = nil;   

            Home *homeObj =  [[Home alloc] initWithNibName:@"Home" bundle:nil];
            UINavigationController *tab1Controller = [[UINavigationController alloc] initWithRootViewController:homeObj];     

            ChatList *chatListObj = [[ChatList alloc] initWithNibName:@"ChatList" bundle:nil];
            UINavigationController *tab2Controller = [[UINavigationController alloc] initWithRootViewController:chatListObj];


            Settings *settingObj = [[Settings alloc] initWithNibName:@"Settings" bundle:nil];
            UINavigationController *tab3Controller = [[UINavigationController alloc] initWithRootViewController:settingObj];  

            self.tabBarController.viewControllers = [NSArray arrayWithObjects: tab1Controller, tab2Controller,tab3Controller, nil];
            self.tabBarController.selectedIndex=0;
            self.tabBarController.delegate = self;


            self.window.backgroundColor=[UIColor clearColor];
            self.tabBarController.view.backgroundColor=[UIColor clearColor];


            self.window.rootViewController = self.tabBarController;

            [self.window makeKeyAndVisible];


    }     

Upvotes: 1

griz
griz

Reputation: 470

I'm not shure if i understand you right. Is you view already conrolled by an view controller? If not, then your action will not work.

you can try to show it modal:

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

otherwise you should read the docs about UINavigationController.

Upvotes: 0

Paras Joshi
Paras Joshi

Reputation: 20551

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];

Upvotes: 1

Related Questions