I'm currently doing this:
timer = [NSTimer timerWithTimeInterval:timeUntilAction target:self selector:@selector(actionToPerform) userInfo:nil repeats:NO];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode:NSRunLoopCommonModes];
But I would like to be able to invalidate that timer. Calling invalidate doesn't seem to do anything and I don't know what else to try, since I can't remove the timer from the NSRunLoop
from any instance methods that I can see for NSTimer
or NSRunLoop
.
How should I set a method (actionToPerform) up to fire after a certain delay (timeUntilAction), but still have the ability to cancel the action, given certain user interaction. The user should also be able to reinitiate the timer before the initial timer (one that was cancelled) was scheduled to go off.
Any suggestions would be great!
Thanks