Switching to a TabBar tab view programmatically?

rottendevice picture rottendevice · Mar 24, 2011 · Viewed 112.9k times · Source

Let's say I have a UIButton in one tab view in my iPhone app, and I want to have it open a different tab in the tab bar of the TabBarController. How would I write the code to do this?

I'm assuming I unload the existing view and load a specific tab view, but I'm not sure how to write the code exactly.

Answer

Jordan picture Jordan · Mar 24, 2011

Try this code in Swift or Objective-C

Swift

self.tabBarController.selectedIndex = 1

Objective-C

[self.tabBarController setSelectedIndex:1];