如何以编程方式设置UITabBarController的选定标签,同时触发shouldSelectViewController在UITabBarControllerDelegate [英] How can I programmatically set selected tab of UITabBarController while also triggering shouldSelectViewController in UITabBarControllerDelegate

查看:1771
本文介绍了如何以编程方式设置UITabBarController的选定标签,同时触发shouldSelectViewController在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆