gpt4 book ai didi

ios - 使用 UiButton 反复更改 UILabel 文本

转载 作者:行者123 更新时间:2023-11-30 12:34:00 26 4
gpt4 key购买 nike

我有几个问题想用标签来显示。当我按下重置按钮时,数组中的下一个问题不会出现。我是否应该将问题放入数组中以便数组中的下一个元素出现?

func theFirstTwoQuestions() {

// the questions will be contained in an Array
// change the question label to one of the array values
// when I press reset the next question will appear

//self.questionLabel.text? = "\(questionsOneTwo)"
questionLabel.isHidden = false
var arrayQuestions = ["What's your name?", "How old are you", "your favorite color is?"]

for question in arrayQuestions {

questionLabel.text = arrayQuestions.first
}

resetButton(sender: UIButton)
arrayQuestions.remove(at: 1)
questionLabel.text = arrayQuestions.first // "How old are you" is now the first question
}
}

最佳答案

这应该可以解决您的问题。

func theFirstTwoQuestions() 
{

// the questions will be contained in an Array
// change the question label to one of the array values
// when I press reset the next question will appear

questionLabel.isHidden = false
var arrayQuestions = ["What's your name?", "How old are you", "your favorite color is?"]
var count = 0


func onTapResetButton(sender: UIButton)
{
self.questionLabel.text = self.arrayQuestions[count] as? String
if(count < arrayQuestions.count-1)
{
count += 1
}
else
{
count = 0
}
}
}

enter image description here enter image description here enter image description here让我知道它是否对你有用。干杯:]

关于ios - 使用 UiButton 反复更改 UILabel 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43109212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com