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.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Feindpak
  • 45
  • 1
  • 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
  • 18,478
  • 8
  • 57
  • 72