简体   繁体   English

我在.enabled按钮快速代码方面遇到麻烦

[英]Im having some trouble with my .enabled buttons swift code

Im working in a mini trivia game, everything is working fine. 我在玩迷你琐事游戏时,一切正常。 The only problem right now is when the user finish answering the questions the buttons still enabled. 现在唯一的问题是,当用户完成回答问题时,按钮仍处于启用状态。

I have created a function to disable and enable buttons and my function for disable buttons is working in my UIButton action but in this case is not working, I don't know if I missing something or Im doing something wrong. 我创建了一个禁用和启用buttons功能,而禁用buttons功能正在UIButton动作中工作,但在这种情况下无法正常工作,我不知道我是否错过了某些东西或Im做错了什么。

PS: Im kind new in swift code This is what I have: 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM