开发者

iPhone how to cancel stop performSelector

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

开发者_JAVA技巧
- (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?


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


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
}


Swift 4.0 version :

NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(yourFunc), object: nil)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜