2017-02-02 65 views
0

我想Segue公司給用戶後,我的主屏點擊UIAlert的「:(」(按鍵部分。然而,當用戶點擊「:(」,視圖不會改變。當我刪除了UIAlert,只有具備SEGUE,該方法適用於它塞格斯到主屏幕。我怎樣才能做到既?警報和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) 

回答

1

對於您需要performSegue用你的行動處理程序,目前你將它設置爲無。

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)