0

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

  • I believe this is a well-known bug. – matt Jun 08 '18 at 16:51
  • @matt actually was reading your book (I took as coobook :) and was waiting you for answer ).. Thanks for comment. Any idea? – José Roberto Abreu Jun 08 '18 at 16:53
  • If it's the same bug, I give my workaround, which is to prevent the user from doing that — i.e. the user _cannot_ switch to another tab while the modal is open. See https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch06p270modalPresentationContext/ch19p607modalPresentationContext/FirstViewController.swift – matt Jun 08 '18 at 16:56
  • 1
    @matt Select your answer as correct, for mentioning that this is a known bug.. In my case, I can't force the TabBar (due to UX) from switching. As a workaround, I did the following: Dismiss the presented controller when the Tab is switched and the modalPresentationStyle is .overCurrentContext. – José Roberto Abreu Jun 08 '18 at 19:42
  • That's good too, obviously! Equally valid. You might give that as an alternate answer, for the record. – matt Jun 08 '18 at 19:44

1 Answers1

2

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
    }
}
matt
  • 515,959
  • 87
  • 875
  • 1,141