Timer decrement gets varied for each page load

前端 未结 2 1644
情深已故
情深已故 2021-01-16 17:55

I have a timer for my project, each time it decrements by 1 second. But if the counter starts working for the second time it gets decremented by 2 seconds and for the third

2条回答
  •  广开言路
    2021-01-16 18:38

    From what you've posted, you're creating multiple timers and not stopping any of them. So after 3 times, you have 3 timers firing each second.

    At a minimum, when the timer hits zero you want to invalidate it:

    [theTimer invalidate]

    But you may also want to consider holding onto the timer you create (in a @property) so that you can invalidate and release it if the user leaves this view some other way before your counter actually goes to zero.

    Hope that helps.

提交回复
热议问题