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.
Asked
Active
Viewed 1,366 times
2 Answers
1
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
0
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)

Bilal
- 18,478
- 8
- 57
- 72