2016-09-01 3 views
0

미니 퀴즈 게임에서 일하고 있습니다. 모든 것이 잘 작동합니다. 지금 당장하는 유일한 문제는 사용자가 단추가 계속 사용할 수있는 질문에 대답하는 것입니다.내 단축키 코드에 약간의 문제가 생겼습니다

내가 비활성화 및 비활성화 buttons 내 기능 내 UIButton 행동에 노력하고 있지만,이 경우에는 뭔가 없거나 임 뭔가 잘못하고 있다면 나도 몰라, 작동하지 않는 buttons을 가능하게하는 함수를 만들었습니다.

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() 
} 
+0

어떻게 버튼을 사용/사용 중지 하시겠습니까? – Jeyamahesan

+0

[여기에 이전 비슷한 질문의 해결책입니다] (http://stackoverflow.com/questions/39240170/how-disable-rest-of-the-buttons-from-an-array-of-buttons-when-button- - 39240503 # 39240503) – aatalyk

+0

내 게시물이 업데이트되었습니다. 버튼을 사용하지 않도록 설정하는 방법이 있습니다. –

답변

1
answerA.enabled = false 

가 문제의 비활성화 기능이 작동하지 마십시오 : SWIFT 코드 임 종류의 새로운이 내가 가진 무엇인가?

+0

무작위 질문 기능 완료 후 내 기능 비활성화 버튼이 작동하지 않습니다. –

관련 문제