简体   繁体   English

如何以编程方式设置UITabBarController的选定选项卡,同时还触发UITabBarControllerDelegate中的shouldSelectViewController

[英]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. 我正在尝试为我的UITabBarController中的选项卡之间的过渡设置动画,当我按下选项卡按钮时,它可以正常工作。 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. 在滑动手势识别器中,未在UITabBarControllerDelegate委托中调用shouldSelectViewController函数,因此不会触发我的动画。

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? 我是否可以通过编程方式以其他方式触发选项卡开关,以便调用shouldSelectViewController函数?

If you have implemented - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController in your tabBarController's delegate than you can call it manually. 如果已在- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController的委托中实现- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController ,则可以手动调用它。

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

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 StoryBoard 在 UITabBarController 中设置选定的选项卡? - How do I set selected tab in UITabBarController using StoryBoard? 如何以编程方式切换到UITabBarController中的另一个选项卡? - How can I switch to another tab in UITabBarController programmatically? 如何以编程方式替换 UITabBarController 的 UITabBar - How can I substitute the UITabBar of UITabBarController programmatically 在UITabBarController上选择选项卡时,如何显示ViewController? - How to present ViewController when tab is selected on UITabBarController? UITabBarController选择的选项卡错误(?) - UITabBarController selected tab bug (?) 如何在Swift的UITabBarController中重新加载/刷新当前选项卡? - How can i reload/refresh the current tab in the UITabBarController in Swift? 如何将UITabBarController的底部标签栏自定义为该确切的模型? - How can I customize the bottom tab bar of UITabBarController to this exact mockup? 为什么设置后UITabBarControllerDelegate为零? - Why is the UITabBarControllerDelegate nil right after I set it? 从UITabBarController(UITabBarControllerDelegate)处理UIBarButtonItem - Handling a UIBarButtonItem from a UITabBarController (UITabBarControllerDelegate) 我可以通过编程方式制作UITabBarController开关选项卡吗? - Can I make a UITabBarController switch tabs programmatically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM