How to check if NSTimer has been already invalidated

前端 未结 4 2007
长情又很酷
长情又很酷 2021-02-19 19:07

I have a NSTimer object that I need to invalidate if a user taps on a button or if they exit a view.

So I have:

[myNSTimer invalidate];
         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-19 19:44

    What I usually do is nil-out the member variable holding the timer, either when it fires, or when I invalidate it. Then you can just do:

    [myNSTimer invalidate]; 
    myNSTimer = nil;
    

    and it'll do the right thing.

提交回复
热议问题