iPhone how to cancel stop performSelector

In my iPhone app, i'm using the following function to do something after some delay

- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;

Is there any way to cancel this performSelector and stop doing some thing after the delay?


Solution 1:

[NSObject cancelPreviousPerformRequestsWithTarget:yourTarget selector:aSelector object: anArgument];

Solution 2:

I thought it might be useful for people to see some actual code, so here are two that I use to stop sounds and swiping when I go to another screen.

- (void)handleSwipeNext {

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(handleSwipeNext) object:nil];

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(playPromptAndTarget) object:nil];

// do some swipe handling stuff
}