0
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let playGameViewController = (storyboard.instantiateViewController(withIdentifier: "PlayGameViewController") as! PlayGameViewController)
        self.navigationController?.pushViewController(playGameViewController, animated: true)

push not worked but I tried present working, I want navigate with push.

3
  • Please explain what exactly is not working. Commented Feb 3, 2020 at 16:49
  • not change view controller Commented Feb 3, 2020 at 17:01
  • Are you sure your navigationController is not nil? Commented Feb 3, 2020 at 17:32

1 Answer 1

4

Try running the below code to know where you have gone wrong.

let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let playGameViewController = storyboard.instantiateViewController(withIdentifier: "PlayGameViewController") as? PlayGameViewController else {
    print("This means you haven't set your view controller identifier properly.")
    return
}
guard let navigationController = navigationController else {
    print("This means you current view controller doesn't have a navigation controller")
    return
}
navigationController.pushViewController(playGameViewController, animated: true)

Try using breakpoints to figure out if any variable is nil. In your case, there is more probability for having your navigationController being nil.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.