我想在用户点击":("(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)
答案 0 :(得分:1)
为此,您需要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)