【发布时间】:2018-12-20 18:55:43
【问题描述】:
我正在尝试开发一款应用简单的游戏。在我的设计中(使用 xcode swift 4.x)我有一个按钮。但是这个按钮实际上是一个3个不同的按钮,每次按下按钮都会改变它的状态和动作。我尝试了一些 if - else 语句,但找不到任何方法。任何建议或任何知识如何实现这种代码。不管怎么说,还是要谢谢你。有一个漂亮的代码。
我写的代码
@IBAction func btnUncoverQuestion(_ sender: RoundedButton) {
btnUncoverQuestion.setTitle(questionArray?[questionNumber].title ?? "No question here", for: .normal)
btnState = btnState + 1
if btnState == 1 {
sender.setTitle("Başlat", for: .normal)
sender.setTitleColor(UIColor.flatWhite, for: .normal)
startTimer()
btnState += 1
if btnState == 2 {
btnState = 0
sender.setTitle("Tamam", for: .normal)
sender.setTitleColor(UIColor.flatWhite, for: .normal)
stopTimer()
let alert = UIAlertController(title: "Sizce cevap doğru mu", message: "Seçimin yap", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Doğru", style: .default, handler: { (trueAction) in
self.playerArray[self.turn].point += 1
self.turn += 1
self.updateQuestionScreen(button: sender)
}))
alert.addAction(UIAlertAction(title: "Yanlış", style: .default, handler: { (wrongAction) in
self.turn += 1
self.updateQuestionScreen(button: sender)
}))
}
}
}
【问题讨论】: