Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically set selected tab of UITabBarController while also triggering shouldSelectViewController in UITabBarControllerDelegate

I'm trying to animate the transitions between tabs in my UITabBarController, which is working fine when I push on the tab buttons. However, when I switch tabs programmatically by calling

[self.tabBarController setSelectedIndex:2]; 

in a swipe gesture recognizer, the shouldSelectViewController function is NOT being called in my UITabBarControllerDelegate delegate, and therefore my animation isn't being triggered.

Is there a way to accomplish what I want? Can I programmatically trigger the tab switch differently perhaps so that the shouldSelectViewController function gets called?

like image 739
herrtim Avatar asked Jul 16 '13 12:07

herrtim


1 Answers

If you have implemented - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController in your tabBarController's delegate than you can call it manually.

[self.tabBarController.delegate tabBarController:self.tabBarController shouldSelectViewController:[[tabBar viewControllers] objectAtIndex:2]]; [self.tabBarController setSelectedIndex:2]; 

Hope this helps.

like image 111
Kapil Choubisa Avatar answered Sep 26 '22 09:09

Kapil Choubisa