UITabBarController's viewControllers present modal controller issue

你说的曾经没有我的故事 提交于 2019-12-02 19:37:42

问题


I have a UITabBarController with 4 viewControllers setup.

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)

Until this point is working fine.

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.

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


回答1:


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
    }
}


来源:https://stackoverflow.com/questions/50765226/uitabbarcontrollers-viewcontrollers-present-modal-controller-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!