我試圖做一個應用程序,如果分數是3,應用程序會顯示一條消息,指出「你輸了」,但保留「3」作爲分數標籤中的數字,直到按下彈出框中的結束遊戲選項,在這一點上,新的比賽得分回到0。我是新來的快,有困難,真的很感謝任何和所有的幫助!我不確定是否爲警報措施做IBAction是正確的做法。Swift:如果按下UIAlertAction,如何使動作發生?
else if rightscorecount == 3 {
let alert = UIAlertController(title: "Game", message: "You Lose!", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "End Game", style: UIAlertActionStyle.default) { UIAlertAction in})
self.present(alert, animated: true, completion: nil)
}
}
@IBAction func test(sender: UIAlertAction) {
rightscorecount = 0
rightscorelabel.text = String(rightscorecount)
}
呈現'UIAlertController'時有一個完成的塊。你可以在那裏添加邏輯。 – Raptor