0
votes

I'd like to present a navigation controller from a tab bar controller's tab's root view controller and have the tabs from the tab bar controller visible.

Here's a photo of an example storyboard: enter image description here

The tab bar controller has a relationship to the ItemOneViewController, which is implemented like this:

import UIKit

class ItemOneViewController: UIViewController {

  private func presentNavigationController() {

    let id = "NavController"
    guard let vc = storyboard?.instantiateViewController(withIdentifier: id) else { return }

    present(vc, animated: true)
  }

  override func viewDidAppear(_ animated: Bool) {

    super.viewDidAppear(animated)
    presentNavigationController()
  }
}

I hoped that by presenting the navigation controller from the root view controller of a tab on a tab bar controller that the navigation controller would be presented behind the tabs, but when I run the described app, this is what the simulator looks like:

enter image description here

This is what the view hierarchy looks like:

enter image description here

I think I remember a previous colleague mentioning that a UINavigationController will replace the view stack, which makes sense but is there anyway to keep it or bring the UITabBarController with it?

I've tried adjusting the presentation style and context but haven't had any luck.

2
why you are not assigning NavController to the UITabBarController root view controller?Nikunj Kumbhani
@NikunjKumbhani because the requirement is that the view controller that is the tab bar's root controller is not a navigation controller.Fred Faust
Please check my answer you need to embed ItemOneViewController with navigation controller so you can bring that with UITabBarItem as well as UINavigationControllerNikunj Kumbhani

2 Answers

0
votes

Try embedding your ItemOneViewController in Navigation Controller instead of embedding you ViewController VC in Navigation Controller.

0
votes

Select ItemOneViewController from storyboard.

Go to the Editor and Embed with Navigation Controller

enter image description here

Your view hierarchy at Storyboard looks Like this :

enter image description here