IPhone how to cancel the stop function Selector

In my iPhone app, I use the following function to do something after some delay

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

Is there a way to cancel this Selector effect and stop doing something after a delay?

+72
iphone
Sep 06 2018-10-10T00:
source share
3 answers
 [NSObject cancelPreviousPerformRequestsWithTarget:yourTarget selector:aSelector object: anArgument]; 
+176
Sep 06 '10 at 5:53
source share

I thought it might be useful for people to see some real code, so here are the two that I use to stop sounds and scroll when I switch 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 } 
+2
Mar 27 '14 at 19:36
source share

Swift 4.0 Version:

 NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(yourFunc), object: nil) 
+1
Nov 11 '17 at 14:11
source share



All Articles