J.Treutlein
J.Treutlein

Reputation: 983

Switching between View Controllers (with simultaneous VCs)

Currently, I have a main ViewController that calls a GameViewController to load a SKScene in front of the main ViewController. I do this in the viewDidLoad of the main ViewController via:

let gameView = self.storyboard?.instantiateViewController(withIdentifier: "Game") as! GameViewController
let top: UIViewController? = UIApplication.shared.keyWindow?.rootViewController
top?.present(gameView, animated: false, completion: nil)

This currently works, I have SKScene displayed on top of a ViewController that displays an image (with an ImageView) in the background.

However, now I want to switch to another ViewController, and I'm not sure how to do this. Things I have tried:

THIS 'PRESENT VIEWCONTROLLLER' WORKED. However, after I called the next ViewController then dismissed it via a segue triggered by a button push in the new ViewController, the new ViewController wouldn't call again with the 'present ViewController' method anymore.

Any ideas on how to successfully switch between ViewControllers (with one of them having a GameViewController simultaneously)?

Upvotes: 2

Views: 65

Answers (1)

LBandach
LBandach

Reputation: 92

I wonder how segues didn't work for u? You need to give segue an identifier and then call it in some function or action(like buttonPressed) or somth. in performSegue(withIdentifier: "urSegueIdentifier", sender: Any?.self) i'm not sure if sender can be nil, maybe try .self?

Upvotes: 3

Related Questions