さて、これまでの出来事の概要を説明しましょう。配列に 3 つの質問があります。「次へ」ボタンを押すたびに、配列内の次の問題にスライドします。私がしたいことは、配列内の次の質問が押されたときに進行状況バーが移動することです。プログレス バーの値に対して何もする必要はありません。実際には設計のために存在するだけです。
現在、コードはすべて設定されているため、[次へ] ボタンを初めて押すと、進行状況バーが値 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)
}