Reset an NSTimer's firing time to be from now instead of the last fire

前端 未结 5 575
面向向阳花
面向向阳花 2021-01-02 13:33

I have a NSTimer that fires with an interval of 3 seconds to decrease a value. When I do an action that increases that value, I want to restart the timer to cou

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 13:57

    Invalidate the timer and recreate it. However, make sure you don't invalidate and release the timer unless you are sure you need to since the run loop retains timers until they are invalidated and then releases them itself.

    In my opinion mixing -performSelector code with timer code leads to multiple execution of the target methods, so I'd stay away from that.

提交回复
热议问题