[英]Im having some trouble with my .enabled buttons swift code
我在玩迷你琐事游戏时,一切正常。 现在唯一的问题是,当用户完成回答问题时,按钮仍处于启用状态。
我创建了一个禁用和启用buttons
功能,而禁用buttons
功能正在UIButton
动作中工作,但在这种情况下无法正常工作,我不知道我是否错过了某些东西或Im做错了什么。
PS:我在快速代码中很新,这就是我所拥有的:
private func pickingRandomQuestion() {
if questions.count > 0 {
questionNumber = random() % questions.count
questionLabel.text = questions[questionNumber].Question
answerNumber = questions[questionNumber].Answer
imgDisplay.image = questions[questionNumber].Img
answerA.setTitle(questions[questionNumber].Answers[0], forState: .Normal)
answerB.setTitle(questions[questionNumber].Answers[1], forState: .Normal)
answerC.setTitle(questions[questionNumber].Answers[2], forState: .Normal)
answerD.setTitle(questions[questionNumber].Answers[3], forState: .Normal)
questions.removeAtIndex(questionNumber)
} else {
finishGame.hidden = false
disableButtons()
//Here is my problem
//NSLog("Done")
//NSLog(String(finalScore))
}
}
@IBAction func btnA(sender: UIButton) {
unhide()
disableButtons()
if answerNumber == 1 {
endLabel.text = "You are Right"
finalScore+=1
} else {
endLabel.text = "You are Wrong"
}
}
@IBAction func btnB(sender: UIButton) {
unhide()
disableButtons()
if answerNumber == 2 {
endLabel.text = "You got it"
finalScore+=1
} else {
endLabel.text = "You are Wrong"
}
}
@IBAction func btnC(sender: UIButton) {
unhide()
disableButtons()
if answerNumber == 3 {
endLabel.text = "You are Correct"
finalScore+=1
} else {
endLabel.text = "You are Wrong"
}
}
@IBAction func btnD(sender: UIButton) {
unhide()
disableButtons()
if answerNumber == 4 {
endLabel.text = "You are Right"
finalScore+=1
} else {
endLabel.text = "You are Wrong"
}
}
@IBAction func nextQuestion(sender: UIButton) {
pickingRandomQuestion()
hide()
enableButtons()
}
answerA.enabled = false
您的问题禁用功能不起作用吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.