0

Why is the navigation bar not displayed immediately, but only after several transitions on the screens?

First Screen

First Screen

Second Screen

Second Screen

Third Screen

Third Screen

Fourth Screen

Fourth Screen

the transition between the storyboard is done by code

let storyboard = UIStoryboard(name: "detail", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "Login") as! TwoViewController
self.present(vc, animated: true)
Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
  • You should probably push your view controller instead of presenting – Scriptable Oct 03 '18 at 09:32
  • but how can I do this? – Sergey Verigin Oct 03 '18 at 09:36
  • like this: `self.navigationController?.push(vc, animated: true)` pushing, pushes onto the navigation stack, but presenting works differently it presents over the top and doesn't use the parents navigation controller – Scriptable Oct 03 '18 at 09:37
  • Possible duplicate of [difference between presentViewController and UINavigationController?](https://stackoverflow.com/questions/14233017/difference-between-presentviewcontroller-and-uinavigationcontroller) – Scriptable Oct 03 '18 at 09:40

1 Answers1

0

Since you are presenting the viewcontroller itself, it won't have any Navigation controller. If you need to present the viewcontroller with navigation controller, present NavigationController instead of viewcontroller.

let storyboard = UIStoryboard(name: "detail", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "navigationControllerID") as! UINavigationController
self.present(vc, animated: true)

OR - wrap VC with NavController programmatically.

let storyboard = UIStoryboard(name: "detail", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "Login") as! TwoViewController
let nav = UINavigationController(rootViewController: vc)
self.present(nav, animated: true)
Lal Krishna
  • 15,485
  • 6
  • 64
  • 84
  • Both will work. But you have to use the same storyboard ID(navigationControllerID) in the code as well as Storyboard. – Lal Krishna Oct 03 '18 at 10:15