Reputation: 45
I have a View Controller called "MenuVC" in my Main.Storyboard file. I want to show this View Controller programmatically from my GameScene.swift file.
Upvotes: 0
Views: 1382
Reputation: 19156
First set the view controller storyboard id in storyboard.
And then
let menuVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MenuVC" as! MenuVC
And if you are using navigation controller
self.navigationController?.pushViewController(menuVC, animated: true)
Or you can present it.
self.present(menuVC, animated: true, completion: nil)
Upvotes: 0
Reputation:
Somewhere in GameScene.swift file:
//...
let vc = self.storyboard?.instantiateViewController(withIdentifier: "MenuVC") as! MenuVC
self.present(vc, animated: true, completion: nil)
//...
But here is the full answer: Swift programmatically navigate to another view controller/scene
Upvotes: 1