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
2010-08-06 14:36:20
+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
2010-08-06 14:37:37
I choose this as acepted answer because it required the least code. :]
2010-08-06 14:43:46
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
2010-08-06 14:37:44