5

I have 4 tabs in my iphone application. When user will click a button in tab-1, I want to move/switch user to another tab suppose tab-2.

How to do that?

user229044
  • 232,980
  • 40
  • 330
  • 338
Ruchir Shah
  • 898
  • 3
  • 13
  • 31

3 Answers3

12

You can use

[self.tabBarController setSelectedIndex:tabIndex];

where tabIndex is the index of the tab you want to switch to.

Jasarien
  • 58,279
  • 31
  • 157
  • 188
  • and how to check which tab is clicked? any delegate method? – Ruchir Shah Mar 25 '10 at 17:27
  • 1
    When switching tabs, the `- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController` delegate method will be called. All of this is available in the documentation. It took me less than a minute to find it and answer your question ;) – Jasarien Mar 25 '10 at 17:35
3

Might also point out that if you are inside a view, you should use super instead of self.

Darkin
  • 221
  • 2
  • 4
2

Swift 3.0 version of @Jasarien answer:

self.tabBarController?.selectedIndex = tabIndex

where tabIndex is the index of the tab you want to switch to.

OxyFlax
  • 451
  • 1
  • 5
  • 16