按下按钮后,仅显示第1个句子

时间:2016-02-19 22:08:24

标签: ios swift uibutton

当我第一次按下按钮时,标签显示"谁是Arnold?"

当我第二次按下BUTTON时,我想要"凯文是谁?"要显示在标签字段上,而不是"谁是Arnold?"

当我第三次按下按钮时,我想要"谁是刘?"要显示在标签字段上,而不是"谁是凯文?"

 @IBAction func answerButtonTapped(send: UIButton){ 

   var question = questionField.text 
   var i = 0 


   var listOfQuestions = ["Who is Arnold?", "Who is Kevin?", "Who is Liu?"] 


    for (i=0; i<=listOfQuestions.count; i++){
        questionField.text = "(listOfQuestions[i])"
    } 
}

1 个答案:

答案 0 :(得分:1)

var counter = 0
var listOfQuestions = ["Who is Arnold?", "Who is Kevin?", "Who is Liu?"]

@IBAction func answerButtonTapped(send: UIButton){ 
  questionField.text = listOfQuestions[counter%listOfQuestions.count] 
  counter++
}