cancelling queued performSelector:afterDelay calls

后端 未结 4 491
甜味超标
甜味超标 2020-12-22 23:29

does anybody know if it is possible to cancel already queued selector events from the event stack or timer stack (or whatever mechanism it is that is utilized by the API) wh

相关标签:
4条回答
  • 2020-12-22 23:51

    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.)

    0 讨论(0)
  • 2020-12-22 23:58
    [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.

    0 讨论(0)
  • 2020-12-23 00:02

    Check the NSRunLoop docs. You want -cancelPerformSelectorsWithTarget:

    0 讨论(0)
  • 2020-12-23 00:06

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

    [NSObject cancelPreviousPerformRequestsWithTarget:self];   
    
    0 讨论(0)
提交回复
热议问题