tags:

views:

1028

answers:

2

In my application i am using NStimer and animation function is call every 3 second.During this timer i want to stop this timer and called another event.How it possible?

+2  A: 

First, you want to keep a pointer to the timer

packetTimer = [[NSTimer timerWithTimeInterval:CONNECTION_TIMEOUT target:self selector:@selector(connectionTimeout:) userInfo:nil repeats:NO] retain];
[[NSRunLoop currentRunLoop] addTimer:packetTimer forMode:NSDefaultRunLoopMode];

If somewhere else in your code you want to cancel it, just call:

[packetTimer invalidate];
coneybeare
A: 
@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;
zaph