1

I have a UITabBarController and need to show the TabBar all the time. In a ViewController which represents a Tab, I present other Viewcontrollers with childViewController.modalPresentationStyle = .overCurrentContext. When I am presenting a ChildViewController (UIViewControllerA0,..), I show a Navigationbar. To go back, i dismiss the currentChildViewController.

This works fine, but the following steps Ends up with a black Screen.

  1. Selecting UIViewControllerA in Tabbar
  2. click something on UIViewControllerA and present(UIViewControllerA0)
  3. UIViewControllerA0 is shown with Navigationbar to go back
  4. Switch to Tab UIViewControllerC or B
  5. Switch to Tab UIViewControllerA -> Child UIViewControllerA0 is still available
  6. Go back on NavigationBar and dismiss UIViewControllerA0
  7. UIViewControllerA is a black <--- ERROR
  8. Switch to tab UIViewControllerB or C and back again -> UIViewControllerA is shown correct

My UIStructure is

UITabBarController
|-UINavigationController
|   --UIViewControllerA Tab
|      --UIViewControllerA0
|      --UIViewControllerA1
|   
|--UINavigationController
|   --UIViewControllerB Tab
|      --UIViewControllerB0
|      --UIViewControllerB1
|
|--UINavigationController
|   --UIViewControllerC Tab
|      --UIViewControllerC0
|      --UIViewControllerC1
|

I have tried several presentationStyles, but I need to show the Tabbar when presenting a "ChildViewController". I also tried to reload the ViewController somehow, but failed and I think this is not the right approach.

Is there a solution for this or is it just not possible to use a TabNavigation like this?

kind regards

Vario
  • 490
  • 4
  • 13
  • So... `UIViewControllerA` is the root VC of a Nav Controller? And on tapping a button in `UIViewControllerA` you `present(UIViewControllerA0)` and "show a NavigationBar"? Meaning, you added a nav bar to the view, right? `UIViewControllerA0` is not embedded in a Navigation Controller? – DonMag Feb 06 '19 at 16:40
  • Ah - found your solution. – DonMag Feb 06 '19 at 16:48
  • UIViewControllerA,B and C are rootViewController of a NavigationViewControllers. The NavigationViewControllers are the viewControllers of the TabViewController. Yes showing a NavigationBar is kinda custom Navigationbar on the top to return. UIViewControllerA0 and others are not embedded just shown with present(...) I mentioned it in the answer how its done now. I found this approach in your possible duplicate link in an answer which was not accepted, but I upvoted it now. – Vario Feb 06 '19 at 16:50

1 Answers1

2

Ok thats weird, this was my start combination of presentationContext and PresentationStyle, but i tried around again and set it back to "start" and now it works with the following settings:

In the UIViewControllerA for example when presenting a Child

childViewController.modalPresentationStyle = .overCurrentContext self.definesPresentationContext = true self.present(childViewController, animated: true, completion: nil)

when closing the ChildViewController I call

childViewController.dismiss(animated: true) {}

I can now stay in a ChildViewController on a tab, switch between tabs and even open other ChildViewControllers on other tabs and when closing a ChildViewController the correct ViewController is shown (UIViewControllerA, UIViewControllerB or UIViewControllerC)

I spent hours now on this and now it seems to be as easy as it could be...

Vario
  • 490
  • 4
  • 13