0

I am trying to open new UIViewController with navigation bar when button is clicked.

But I can not see the navigation bar. I only see what I gave the background color.

Here is my code to show my UIViewController

@objc func ActionButtonTapped() {
    let nav = UINavigationController(rootViewController: UploadTweetController())
    nav.modalPresentationStyle = .fullScreen
    present(nav, animated: true, completion: nil)
}
    

and viewDidLoad function of controller

override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .red
} 

I also tried nav.isNavigationBarHidden = false and nav.NavigationBar.isHidden = false but did not work.

Tolga KÜÇÜK
  • 123
  • 2
  • 10

1 Answers1

0

Your code is working fine. But by default the navigation bar is transparent. And you have given it no content. So it is there but you can't see it.

(Use the View Debugger if you don't believe me.)

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • So, what should I do to see. I add ` navigationController?.navigationBar.isTranslucent = false navigationController?.navigationBar.backgroundColor = .systemGray` to viewDidLoad and as you said I can see the navigation bar but this time my navigation bar does not cover the top of screen and I see black and gray colors on the navigation bar. – Tolga KÜÇÜK Jan 03 '22 at 19:14
  • I don't know what you're seeing after that change. It isn't the change I would have made; personally, I would use UINavigationBarAppearance (as explained in many existing answers already). – matt Jan 03 '22 at 19:18
  • For example see https://stackoverflow.com/questions/70571236/uinavigationcontroller-status-bar-color-is-transparent – matt Jan 03 '22 at 22:06
  • Hi again @matt, sorry for late answer. I have tried your recommended solution and it worked. Thank your for suggestion and attention – Tolga KÜÇÜK Jan 04 '22 at 18:01