我是 iOS-Swift 的新手,在 score < 3
时不显示消息:“失败!再玩一次” .
func discussScore(sender: AnyObject){
// after asking all questions, if score >=20, the player accesses stage 2
if (questionField.text == listOfQuestions[4]) {
if (score >= 3) {
//go to next step
}
if (score < 3) {
alertMessageWrong("Fail! Play Again") // (here's my problem)
}
}
}
func alertMessageWrong(theMessage2: String) {
let alertController = UIAlertController(title: " ", message:theMessage2, preferredStyle: UIAlertControllerStyle.Alert)
alertController.view.tintColor = UIColor.redColor()
alertController.addAction(UIAlertAction(title:theMessage2, style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
最佳答案
首先,我会在这一行放置一个断点:
if (questionField.text == listOfQuestions[4])
并逐步查看每一行以查看采用了哪条路线...您可以了解如何调试 here .
要检查您是否回答了正确的问题,最好使用“步长”整数而不是比较字符串。在回答每个问题后增加此整数。然后你可以检查你是否在做最后一个问题:
if currentStep >= listOfQuestions.count { ... }
其次,如果您这样做,代码会更简洁:
let minimumScore = 3
if score < minimumScore {
showAlert()
return
}
// go to next step.
关于ios - 消息 : "Fail! Play Again" does not display when score < 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35749903/