Hello! I implement the application with workouts. In general, I add a button to the project further (Rewind) and there is a problem, I can not figure it out. The button further should work only when the exercise is on. When you click on further it is conceived that the timer stops with animation and returns to its original state, the names of the exercises are changed to the next ones in the list. But it turns out that at the start after scrolling the timer and animation start their movement for one second and return to their original position, then the countdown and animation again begin their task, but having reached the end completely. Without pressing the scrolling exercises begin correctly, without returns. I have a lot of code, so please see a piece of the project for clarity, https://yadi.sk/d/ppI7iRCy3EPEEt already broke my head ... Do not pay attention to the ending of the workout, when testing the project in the simulator ... Thank you in advance

  • can step by step how to reproduce the problem - Max Mikheyenko
  • I didn’t understand the question a bit ... If you see this problem on the simulator, then after pressing play (start of exercises) the first exercise begins, then by clicking on the skip (skip) we go to the second exercise. And at this moment by clicking on the play, starting the second exercise, the countdown from the five to zero begins, and after a second, instead of displaying the four, the timer returns to the top five, the same thing happens with the animation of progress. - Artur Skachkov

1 answer 1

short answer:

in line 191 in the view controller instead of exersiseTime = 0 write exersiseTime = 5

Long answer:

After pressing the next button, you reset the exersiseTime = 0 timer and set the text in timerLabel.text to five. At this point, you have a view and the model starts to differ - on the screen you see 5, and actually 0. next, when you start the exercise, after the first timer is triggered, exersiseTime becomes = -1 and starts your beautiful animation returning the progress bar to the beginning and after that the countdown from 5 to 0 occurs.

How to debug this?

Since you yourself said that this is happening, a second after the start of the timer, you can set breakpoint in the counting function, which is called every second and from there go line by line; and immediately find out that exersiseTime = -1 and the program immediately enters the if exersiseTime == -1 { branch if exersiseTime == -1 { and there it is immediately clear that after switching to the next one, the timer was not returned back.

  • Corrected as they said, now after pressing next, it starts as it should be, without returns, but until this exercise (which was jumped) does not repeat twice in a row, it does not end and does not allow him to jump over - Artur Skachkov
  • after pressing the next button you do not increase the index of the current exercise, simply display the information on the next exercise. Those. the first exercise is performed again, and only after that does it move to the second. This is the second bug related to the fact that you update the view and do not update the model. - Max Mikheyenko
  • one
    in tappedNext put i += 1 after the first line, then fix all the labels so that they show the correct values ​​(you have i + 2 there, fix it on i + 1) - Max Mikheyenko
  • Thank you very much! Now everything works correctly! - Artur Skachkov