0

In my UITabbar Application (created using xCode) I have 6 tab buttons. In the first tab I have 5 UIButttons which should load other 5 corresponding tabs when clicked on the buttons. First one is the index/home page others are the different modules with a nib file for each of the modules.

My question is when clicked on the Button1 it should load tabbar 1(index's start from 0 for Tabbar App) and when clicked on the Button2 it should load tabbar 2 and so on.

In the IB action I have written the following code

-(IBAction)Button1:(id)sender
{
    firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstView"bundle:nil];  

    [self.view addSubview:firstViewController.view];

}

To the best of my knowledge this paints(adds) the firstViewController on the tabbar 0 instead of calling the tabbar index 1.

Should I try

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;

If so where should I write this?

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
Kris
  • 35
  • 2
  • 8

1 Answers1

0

Create a ParentTabbarController, which will derive from UITabBarController. Now place the subcontroller in this ParentTabBarController. Define a method in ParentTabBarController which will take care of placing the tab view in corresponding tabbar.

From your action on button tap you need to ping the parent controller method with the argument (may be index like 1,2 etc) which will place the tab on the basis of the provided index. I hope this will help you identify the place to place the above mentioned code.

UPT
  • 1,490
  • 9
  • 25