0

I want to segue to my home screen after the user clicks the ":(" (button part of the UIAlert. However, when the user clicks the ":(", the view does not change. When I remove the UIAlert, and only have the segue, the method works in that it segues to the home screen. How can I do both?

let gameOver = UIAlertController(title: "BOOM", message: "You hit a mine! Game over.", preferredStyle: UIAlertControllerStyle.alert)
gameOver.addAction(UIAlertAction(title: ":(", style: UIAlertActionStyle.default, handler: nil))
self.present(gameOver, animated:true, completion: nil)       
self.performSegue(withIdentifier: "homeScreen", sender:self)
Shekar
  • 240
  • 1
  • 5
  • 14

1 Answers1

1

For that you need to performSegue with your action handler, currently you are setting it to nil.

let gameOver = UIAlertController(title: "BOOM", message: "You hit a mine! Game over.", preferredStyle: .alert)
gameOver.addAction(UIAlertAction(title: ":(", style: .default) { action in 
     self.performSegue(withIdentifier: "homeScreen", sender:self)
})
self.present(gameOver, animated:true)
Nirav D
  • 71,513
  • 12
  • 161
  • 183