cancelling queued performSelector:afterDelay calls

大兔子大兔子 提交于 2019-11-29 19:29:15
stefanB
[NSObject cancelPreviousPerformRequestsWithTarget:]

or

[NSObject cancelPreviousPerformRequestsWithTarget:selector:object:]

The target is the original object on which performSelector:afterDelay: was called.

For example:

// schedule the selector
[self performSelector:@selector(mySel:) withObject:nil afterDelay:5.0];
// cancel the above call (and any others on self)
[NSObject cancelPreviousPerformRequestsWithTarget:self];

See apple docs, it's right at the end of the performSelector:withObject:afterDelay: description.

Marco Mirisola

In order to cancel all previous perform requests, you may use :

[NSObject cancelPreviousPerformRequestsWithTarget:self];   
Irene

If you are looking for "performSelector" to have its matching "cancelPreviousPerformSelector"... it doesn't. (Ugh, Apple, why do you do that to me???)

The, er, ah, "matching" methods are:

performSelector

cancelPreviousPerformRequestsWithTarget

(Just to make it extra hard to remember, without searching the docs.)

NSResponder

Check the NSRunLoop docs. You want -cancelPerformSelectorsWithTarget:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!