Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop/invalidate NStimer

I am using

 [NSTimer scheduledTimerWithTimeInterval:0.1f
                                  target:self
                                selector:@selector(update)
                                userInfo:nil
                                 repeats:YES];

I want to stop calling this timer one.

viewDidDisappear

How can i do that? invalidate?

like image 432
Shishir.bobby Avatar asked Mar 02 '13 03:03

Shishir.bobby


1 Answers

Declare NSTimer *myTimer in .h file.

Assign instance as tom said like this

myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1f
                                     target:self
                                   selector:@selector(update)
                                   userInfo:nil
                                    repeats:YES];

Stop and Invalidate using this

- (void) viewDidDisappear:(BOOL)animated
{
    [myTimer invalidate];
    myTimer = nil;
}
like image 76
βhargavḯ Avatar answered Oct 23 '22 11:10

βhargavḯ