views:

34

answers:

3

How can I make a timer that counts down from 3 and then runs a method? How would I do that?

+1  A: 

Is that different from a timer counting from 0 to 3? It will still wait three seconds, either way.

[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(myMethod:) userInfo:nil repeats:NO];

Grimless
+1  A: 

Better way might be to use performSelector:withObject:afterDelay: method:

[self performSelector:@selector(myMethod) withObject:nil afterDelay:3.0f];

Or in case method takes 1 parameter:

[self performSelector:@selector(myMethod:) withObject:parameter afterDelay:3.0f];

If method takes multiple parameters you'll need to use NSInvocation class

Vladimir
I choose this as acepted answer because it required the least code. :]
A: 
- (void) handleTimer: (NSTimer *) timer
{
    do some work here...
} // handleTimer

// at some point in your controller
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 3.0
                 target: self
                 selector: @selector(handleTimer:)
                 userInfo: nil
                 repeats: NO];
slf