Friday 8 March 2013

How to stop/invalidate NStimer


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


invalidate Method of NSTimer is use for stop timer
- (void) viewDidDisappear:(BOOL)animated 
{
        [super viewDidDisappear:animated];
        [self.timer invalidate];
        self.timer = nil;
}
If you are not ARC then don't forget [self.timer release];
OR
When we go nextView then we write this code of that method scope
        [self.timer invalidate];

No comments:

Post a Comment