Change UITabBar Selected Tab

15,054

Solution 1

Thanks for the help, You guys helped me in the right direction I ended up using the App delegate to access the UITabBarController. This is what it looked like.

 Motel_6AppDelegate *appDelegate = (Motel_6AppDelegate*) [[UIApplication sharedApplication] delegate];
    [appDelegate.rootController setSelectedIndex:1];

Solution 2

Read the documentation. From within the search controller, you can call:

self.tabBarController.selectedViewController = self;

UITabBarController also has a selectedIndex property if that's more convenient for you. viewDidLoad is probably the wrong place to put this code in, though, as it might not be called every time the search controller is displayed. You should rather select the tab directly from inside the action that is called when the user taps the search button on the home screen.

Solution 3

Use tabBarController.selectedIndex = intIndex; // inyour case 1

use this code inside applicationDidLaunch

Share:
15,054
Barrett
Author by

Barrett

I dont take showers only blood baths

Updated on June 05, 2022

Comments

  • Barrett
    Barrett almost 2 years

    I have an app that I created as a Tab Bar Application, and there are 3 tabs (Home, Search, My Account). The Home view loads with some info and a search button. The search button then takes the user to the Search View, but since the user didn't select the tab the selected tab is still the Home tab. How do I change the selected tab from the Home to the Search once the Search viewDidLoad?