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: 方法/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!