在 Swift 中增加 UIButton 按下时的进度条值
Increase a Progress bar value on a UIButton press in Swift
好的,让我向您概述一下到目前为止发生的情况。我在一个数组中有三个问题。每按一次'Next'按钮,就会滑动到数组中的下一个问题。我想要发生的是,当按下数组中的下一个问题时,它会移动进度条。我不需要对进度条的值做任何事情,它只是为了设计而存在。
目前,我已经设置好了代码,所以当你第一次按下下一步按钮时,它会将进度条移动到值 0.333,但是当你再次按下它时,它不会再移动,它只是停留在原处。
有人可以帮忙吗,因为我已经尝试解决这个问题一段时间了,只是运气不好。我的代码显示了我必须使其最初移动的内容如下:
@IBOutlet var progressStatus: UIProgressView!
@IBAction func nextButton(sender: AnyObject) {
// Displays the questions in array and displays the placeholder text in the textfield
if currentQuestionIndex <= questions.count && currentPlaceholderIndex <= placeholder.count {
currentQuestionIndex++
currentPlaceholderIndex++
progressStatus.setProgress(0.333, animated: true)
buttonLabel.setTitle("Next", forState: UIControlState.Normal)
}
提前致谢!
回答我的问题的代码:
if currentQuestionIndex == 0 {
progressStatus.setProgress(0.333, animated: true)
} else if currentQuestionIndex == 1 {
progressStatus.setProgress(0.666, animated: true)
} else {
progressStatus.setProgress(1, animated: true)
}
我不确定目前的修复方法是什么,因为我目前仍在学习 swift,所以请给您一个想法。但我认为它是你设置的值,0.333。使用您现在拥有的代码,您将其设置为值 0.333,而不是增加 0.333。也许您可以使用 if 循环遍历问题。比如,如果问题 == 1,setProgress(0.333),如果问题 == 2,setProgress(0.666)
好的,让我向您概述一下到目前为止发生的情况。我在一个数组中有三个问题。每按一次'Next'按钮,就会滑动到数组中的下一个问题。我想要发生的是,当按下数组中的下一个问题时,它会移动进度条。我不需要对进度条的值做任何事情,它只是为了设计而存在。
目前,我已经设置好了代码,所以当你第一次按下下一步按钮时,它会将进度条移动到值 0.333,但是当你再次按下它时,它不会再移动,它只是停留在原处。
有人可以帮忙吗,因为我已经尝试解决这个问题一段时间了,只是运气不好。我的代码显示了我必须使其最初移动的内容如下:
@IBOutlet var progressStatus: UIProgressView!
@IBAction func nextButton(sender: AnyObject) {
// Displays the questions in array and displays the placeholder text in the textfield
if currentQuestionIndex <= questions.count && currentPlaceholderIndex <= placeholder.count {
currentQuestionIndex++
currentPlaceholderIndex++
progressStatus.setProgress(0.333, animated: true)
buttonLabel.setTitle("Next", forState: UIControlState.Normal)
}
提前致谢!
回答我的问题的代码:
if currentQuestionIndex == 0 {
progressStatus.setProgress(0.333, animated: true)
} else if currentQuestionIndex == 1 {
progressStatus.setProgress(0.666, animated: true)
} else {
progressStatus.setProgress(1, animated: true)
}
我不确定目前的修复方法是什么,因为我目前仍在学习 swift,所以请给您一个想法。但我认为它是你设置的值,0.333。使用您现在拥有的代码,您将其设置为值 0.333,而不是增加 0.333。也许您可以使用 if 循环遍历问题。比如,如果问题 == 1,setProgress(0.333),如果问题 == 2,setProgress(0.666)