ios4timerios-simulatornstimeriphone-sdk-4.1

How to stop/invalidate a NSTimer


Possible Duplicate:
NSTimer doesn't stop

How can I stop / invalidate a NSTimer??

Below is the code:

- (void)autoscrollTimerFired:(NSTimer*)timer {

   NSLog(@"Each & Every Time this MEthods is called Even if I try to invalidate it in viewDidDisappear "); 
}


- (void)viewWillAppear:(BOOL)animated{

    if (autoscrollTimer == nil) {
        autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:(35.0/1000.0)
                                                           target:self
                                                         selector:@selector(autoscrollTimerFired:) 
                                                         userInfo:nil 
                                                          repeats:YES]; // To repeat this thread it's as per my requirement
    }
}

-(void) viewWillDisappear:(BOOL)animated {

    [autoscrollTimer invalidate];
}

So,please suggest me to do this ...


Solution

  • I had the same problem. I guess you have made it as property nonatomic, retain?

    Please do this:

    [self.autoscrollTimer invalidate];
    

    Thanks.