iOS Swift instantiate view controllers from Storyboard

You can use a storyboard object to instantiate the initial view controller or instantiate other view controllers that you want to present programmatically using the identifier.

Swift instantiate view controllers from Storyboard

let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

//Get Initial ViewController
let mainViewController = mainStoryboard.instantiateInitialViewController()

//Get ViewController by Id
//Make sure you give the view controller in your storyboard a Storyboard ID inside the identity inspector.
let mainViewController = mainStoryboard.instantiateViewController(withIdentifier: "myId")

No comments:

Post a Comment

NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.