[英]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.