Home > Net >  How to modally present a navigation controller in Swift?
How to modally present a navigation controller in Swift?

Time:03-24

I am trying to present a navigation controller modally,the thing is my navigation bar is not showing any baritems... any ideas? This is my code. If I add a backgroud color to the navigation bar it actually shows, but not the buttons... Please help!

if let navigationController = baseController as? UINavigationController {
    if UIScreen.main.traitCollection.userInterfaceIdiom == .phone {
        navigationController.present(webViewController, animated: true, completion: nil)
    } else {
        let webNavigationController = UINavigationController(rootViewController: webViewController)
        webNavigationController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(cancelTapped))
        webNavigationController.isNavigationBarHidden = false
        webNavigationController.modalPresentationStyle = .overFullScreen
        navigationController.present(webNavigationController, animated: true, completion: nil)
    }
}

CodePudding user response:

This line is wrong:

webNavigationController.navigationItem.leftBarButtonItem = UIBarButtonItem(...

It is not webNavigationController whose navigationItem dictates the presence of bar button items, but rather webViewController.

  • Related