我想在用户单击":("后转到我的主屏幕(UIAlert 的按钮部分。但是,当用户单击":("时,视图不会更改。当我删除 UIAlert 并且只有 segue 时,该方法的工作原理是它会连接到主屏幕。我怎样才能同时做到这两点?
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)
为此,您需要使用操作处理程序进行performSegue
,目前您将其设置为 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)