Matrosov Alexander Matrosov Alexander - 8 months ago 43
iOS Question

How do I set selected tab in UITabBarController using StoryBoard?

How can I switch to some tab in

using StoryBoard? I have tried the code below but without success (the tab is not selected):

self.tabBar.selectedIndex = 3;

Honestly I used nib files without StoryBoard and this code above worked fine in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions
:(NSDictionary *)launchOptions

but now I can't set the tab programatically. Maybe there is another problem that is not connected to selecting the tab. How can I switch tabs?


Grab your instance of UITabBarController then set the selectedViewController property:

yourTabBarController.selectedViewController=[yourTabBarController.viewControllers objectAtIndex:3];//or whichever index you want