NSTimer Not Stopping When Invalidated

后端 未结 7 1337
情书的邮戳
情书的邮戳 2021-01-05 05:22

I have the following code in my .h file:

#import 
#import 
#import 

        
7条回答
  •  时光取名叫无心
    2021-01-05 05:50

    I have an approach for stopping or deactivate the timer, Before apply this make sure that you tried all the cases as mentioned above so you can also understand that why this approach used at last.

     // Instead of self use NSTimer class, it will not provide you any crash and in selector placed any empty function and setRepeats to NO
    
    self.messageTimer = [NSTimer scheduledTimerWithTimeInterval:100.0
                           target:NSTimer selector:@selector(emptyFunctionCalling)
                                                                       userInfo:nil
                                                                        repeats:NO];
    [self.messageTimer invalidate];
     self.messageTimer = nil;
    

    So whenever the case occured that timer will not stopping then entering in this code the timer will stops permanently.

提交回复
热议问题