Change Selected UITabBar Tab

I have an application that I created as a tab bar application, and there are 3 tabs ("Home", "Search", "My Account"). In the "Start" mode, the information and the search button are loaded. The search button then brings the user to the search box, but since the user has not selected a tab, the selected tab is still the "Home" tab. How to change the selected tab from "Home" to "Search" after searching for "View"? "?

+3
source share
4 answers

Thanks for the help, you guys helped me in the right direction, I ended up using the application delegate to access the UITabBarController. Here is how it looked.

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

Read the documentation. Inside the search controller, you can call:

self.tabBarController.selectedViewController = self;

UITabBarControlleralso has a property selectedIndexif it is more convenient for you. viewDidLoadThis is probably the wrong place to enter this code, as it may not be called every time the search controller is displayed. You must select the tab directly from the action that is called up when the user clicks the search button on the main screen.

+4
source

tabBarController.selectedIndex = intIndex;//inyour case 1

applicationDidLaunch

+3

iOS7 Xcode 5.

- (IBAction)cancelButtonPressed:(id)sender
{
    [self.tabBarController setSelectedIndex:1];
}
0

Source: https://habr.com/ru/post/1788558/


All Articles