Answer the question
In order to leave comments, you need to log in
How to repeat the timer countdown cycle?
When increasing cycles, more than one, at the end of each cycle, you must show the first element from the array list in this label, and at the end of the last cycle, show the phrase about the end of the workout. I can not find the conditions for labels to be displayed correctly when changing the number of cycles.
let exersiseName = ["БЕГ", "ПРЫЖКИ", "ПРИСЕДАНИЯ"]
@IBOutlet var nameExersiseLabel = UILabel()//лэйбл с названием упражнения
@IBOutlet var timerLabel = UILabel()//лэйбл секундомера
@IBOutlet var nextExersiseLabel = UILabel()
var timer = NSTimer()
var exersiseTime = 30
var timerRunning = false
var i = 0
var sets = 2 //вводим переменную количества циклов которая будет меняться
var count = 0
func Counting(){
exersiseTime -= 1
timerLabel.text = "\(Int(exersiseTime))"
if exersiseTime == -1 {
i += 1
exersiseTime = 30
timerLabel.text = "\(Int(exersiseTime))"
if i + 1 > exersiseName.count { //Конец тренировки
count += 1
if (count >= sets) {
timerLabel.text = "0"
timer.invalidate()
timerRunning = false
} else {
i = 0
}
}
if i + 1 < exersiseName.count { //Ход тренировки
nameExersiseLabel.text = exersiseName[i] as? String
nextExersiseLabel.text = ("\(exersiseName[i + 1])")
}
if i + 1 == exersiseName.count { //Последнее упражнение в тренировке
nameExersiseLabel.text = exersiseName[i] as? String
// не могу подобрать условия ниже для того чтобы корректно отображались лэйблы при смене количества цыклов
nextExersiseLabel.text = ("\(exersiseName[0])") // Отображать при наличии последующих циклов
nextExersiseLabel.text = "WORKOUT COMPLETE!" //Отображать при выполнении последнего цыкла
}
}
}
Answer the question
In order to leave comments, you need to log in
Get a variable var cycles = 0
, put the condition if i + 1 > exersiseName.count
first and modify it like this:
if i + 1 > exersiseName.count { //Конец цикла
count+=1
if (count >= sets) {
timerLabel.text = "0"
timer.invalidate()
timerRunning = false
}else{
i = 0
}
} //важно: не надо ставить здесь else
if ....
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question