How to stop NStimer event?

Mansi picture Mansi · Sep 15, 2009 · Viewed 72.7k times · Source

Possible Duplicate:
NSTimer doesn't stop

In my application I am using NStimer to call an animation function every 3 seconds. I want to stop this timer and called another event while the timer is still running. Is this possible?

Answer

zaph picture zaph · Sep 15, 2009
@interface
    NSTimer *autoTimer;

@implementation

// Start timer
    autoTimer = [NSTimer scheduledTimerWithTimeInterval:(3.0)
        target:self 
        selector:@selector(autoTimerFired:) 
        userInfo:nil 
        repeats:YES];

// Stop timer:
    [autoTimer invalidate];
    autoTimer = nil;