0

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.

aydinugur
  • 1,202
  • 2
  • 14
  • 21
Feindpak
  • 45
  • 6

2 Answers2

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.

enter image description here

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
  • 17,228
  • 8
  • 53
  • 69