Tahlil
Tahlil

Reputation: 2731

Tab switching in IOS 5

Hi I have two tabs in my application. I implemented the tabs with UITabBarController. I can switch between the two tabs using the tab bar in the application. But I want to use buttons to switch between tabs. Both tab will contain one button. Pressing the button in any tab will switch to the other tab. I cant seem to find any way to do this.Thanks.

Upvotes: 0

Views: 64

Answers (2)

Nitin Gohel
Nitin Gohel

Reputation: 49730

you can do like:-

BOOL isFirstIndexSelected;
-(IBAction)ActionSwitchTab
{

    if(isFirstIndexSelected=YES)
    {
      [self.tabBarController setSelectedIndex:1];
      isFirstIndexSelected==NO;
    }
    else

    {
    [self.tabBarController setSelectedIndex:0];
          isFirstIndexSelected==YES;

    }

}

As for above code its for only one button clicking changing tab. But if you set Diffrent button for Diffrent tab you just need to implements each button action and set tab manually like :-

[self.tabBarController setSelectedIndex:0];

Upvotes: 1

Michael Dautermann
Michael Dautermann

Reputation: 89559

If you want to switch between tabs using code, it can be as simple as changing the "selectedIndex" property of your UITabBarController (provided that controller is hooked up to an outlet your view controller can address).

Upvotes: 3

Related Questions