双击UITabBarController时防止自动popToRootViewController [英] Prevent automatic popToRootViewController on double-tap of UITabBarController
问题描述
UITabBarController的默认行为是在第二次点击特定选项卡时将包含的UINavigationController弹出到根视图控制器。我有一个特殊的用例,我希望这不会自动运行,而且我很难弄清楚如何防止这种情况。
The default behavior of a UITabBarController is to pop the contained UINavigationController to the root view controller when a particular tab is tapped a second time. I have a particular use case where I'm wanting this to not work automatically, and I'm having a hard time figuring out how to prevent this.
有没有人跑过进入这个,如果是这样,你做了什么?我是否需要继承UINavigationController并覆盖popToRootViewController或者是否有更简单的方法?
Has anyone run into this, and if so, what did you do? Do I need to subclass UINavigationController and override popToRootViewController or is there a simpler way?
推荐答案
使用 tabBarController:shouldSelectViewController :方法UITabBarControllerDelegate /rel =noreferrer> UITabBarControllerDelegate协议。
Use the tabBarController:shouldSelectViewController: method of the UITabBarControllerDelegate protocol.
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
return viewController != tabBarController.selectedViewController;
}
不要忘记将标签栏控制器的委托设置为对象实际上实现了这种委托方法。
Don't forget to set the delegate of the tab bar controller to the object that actually implements this delegate method.
这篇关于双击UITabBarController时防止自动popToRootViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!