Prevent automatic popToRootViewController on double-tap of UITabBarController(防止双击 UITabBarController 时自动 popToRootViewController)
问题描述
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:防止双击 UITabBarController 时自动 popToRootViewController
基础教程推荐
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
