0

I have a simple game app that I developed in Swift. I have a button in an options screen that will allow the user to quit the current game and return to the start screen. I have looked into several ways to do this, but I'm not sure which way is the correct way.

Option 1: I created a exit function and defined that function in the main ViewController, it looks something like this:

   @IBAction func unwindToHome(s:UIStoryboardSegue) {
    println("unwind to home");
}

Then I just controlled drag to the exit icon from the quit button inside the Options View Controller. This works, but gives me some unexpected results. As it's unwinding through my View Controllers, it's triggering code along the way, which by the time it gets back to the root VC there are some errors that are happening.

Option 2: Control drag from the quit button back to the root VC. This works, and doesn't cause any errors but I just don't know if this is good practice. Does this remove all the other VC's from the stack, or am I just starting a new game on top of the old one?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
icekomo
  • 9,328
  • 7
  • 31
  • 59

1 Answers1

0

In Option 2, when you control drag from the quit button to the root VC, which type of segue are you selecting?

I would normally say Option 1 all the way, but a workaround is to not use an unwind segue. Rather, just call an IBAction when the button is tapped and inside that method, call

self.navigationController?.popToRootViewControllerAnimated(true)
Josh Gafni
  • 2,831
  • 2
  • 19
  • 32