简体   繁体   中英

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.

PS: Im kind new in swift code This is what I have:

 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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