简体   繁体   中英

Show navigation to Controller programatically

I am changing a menu VC over from StoryBoard to programatic operation.

When I want to load another VC I was using the Action Segue "Show".

The temporary code I am using works but pops the VC over the top. Can you action the "Show" equivalent programatically, and if so how?

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "SunriseSunsetResultsViewController")
self.present(newViewController, animated: true, completion: nil)

To do what a Show segue used to do, replace present with show :

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "SunriseSunsetResultsViewController")
self.show(newViewController, sender: self)

Note, however, that this will do the same thing as present unless self.navigationController is not nil . In other words, you cannot do the sideways navigation you were doing before unless a navigation controller is in charge of the interface.

Instead of show you could say pushViewController etc., but the same caveat applies. Only a navigation controller can do what you were doing previously.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM