我的.enabled按钮swift代码有点麻烦

时间:2016-09-01 07:53:35

标签: ios swift uibutton

我在迷你琐事游戏中工作,一切正常。现在唯一的问题是用户完成对按钮仍然启用的问题的回答。

我已经创建了一个禁用和启用buttons的功能,我的buttons禁用UIButton功能正在我的 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() } 行动中起作用,但在这种情况下无效,我不知道如果我错过了什么或我做错了什么。

PS:我是swift代码的新手这就是我所拥有的:

{{1}}

1 个答案:

答案 0 :(得分:1)

answerA.enabled = false

你的问题禁用功能不起作用吗?