如何以编程方式设置UITabBarController的选定标签,同时触发shouldSelectViewController在UITabBarControllerDelegate [英] How can I programmatically set selected tab of UITabBarController while also triggering shouldSelectViewController in UITabBarControllerDelegate
问题描述
我想在我的UITabBarController中的标签之间的转换动画,这是工作正常,当我按标签按钮。但是,当我通过调用
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];
,在我的UITabBarControllerDelegate委托中没有调用shouldSelectViewController函数,因此我的动画未被触发。
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?
推荐答案
如果你已经实现了 - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
在您的tabBarController委托中,比您可以手动调用。
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];
希望这有帮助。
这篇关于如何以编程方式设置UITabBarController的选定标签,同时触发shouldSelectViewController在UITabBarControllerDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!