UITabBarController的viewControllers出现模态控制器问题 [英] UITabBarController's viewControllers present modal controller issue

查看:150
本文介绍了UITabBarController的viewControllers出现模态控制器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有4个viewControllers设置的UITabBarController.

I have a UITabBarController with 4 viewControllers setup.

其中一个控制器具有一个按钮,该按钮为另一个控制器(包装在UINavigationController上)提供以下设置:

One of the controller has a button that present another controller (wrapped on UINavigationController) with the following setup:

self.definesPresentationContext = true
navController.modalPresentationStyle = .overCurrentContext
navController.modalTransitionStyle = .crossDissolve
self.present(navController, animated: true)

直到这一点正常为止.

现在,如果我切换到另一个选项卡(在打开前一个模态的同时),然后再次返回到显示模态的选项卡(屏幕仍然存在,就可以了).然后,如果我(从按钮)关闭模态,则模态被取消,但控制器视图已消失(白色),然后,如果我切换到另一个选项卡并再次返回到该选项卡,则视图将正确加载.

Now if I switch to another tab (while the previous modal is open), and return again to the tab that presented the modal (The screen is still there, that's ok). Then if i close the modal (from a Button), the modal is dismissed but the controller view's has gone (white), then if I switch to another tab and return to the tab again, the view load correctly.

注意:在这种情况下,我需要overCurrentContext,不想阻塞UITabBarController(使用fullScreen).也可以尝试使用.currentContextcustom

Note: For this case, I need overCurrentContext, don't want to block UITabBarController (with fullScreen).. Also try with .currentContext, custom

推荐答案

如果这与我演示的错误相同

If this is the same bug that I demonstrate here, the workaround I give is to prevent the user from switching to another tab while this tab is showing the presented view controller:

override func viewDidLoad() {
    super.viewDidLoad()
    self.tabBarController?.delegate = self
}
extension FirstViewController : UITabBarControllerDelegate {
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        return self.presentedViewController == nil
    }
}

这篇关于UITabBarController的viewControllers出现模态控制器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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