开发者

How to stop performing selector?

开发者 https://www.devze.com 2023-03-23 05:43 出处:网络
Im trying to figure out how to stop performing a selector I can start one by doing this [self performSelector:@selector(vibe)];

Im trying to figure out how to stop performing a selector

I can start one by doing this

            [self performSelector:@selector(vibe)];

But im tryi开发者_如何学运维ng to figure out how i can stop one.

Any help would be very much appreciated..Thanks!


The performSelector: method is equivalent to sending a selector message directly to the receiver, so it cannot be canceled. I.e., these two lines have the same effect:

[self performSelector:@selector(vibe)];
[self vibe];

The cancelPreviousPerformRequestsWithTarget: (and similar) methods can only cancel selector messages which are not performed immediately. You can send such a message via the performSelector:withObject:afterDelay: (and similar) methods.

See Table 3-2 of the Run Loop Management section of Apple's Thread Programming Guide for more information.


[NSObject cancelPreviousPerformRequestsWithTarget:self];
// or
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(vibe) object:nil];


It's not immediately obvious, but I believe the following should work:

[NSObject cancelPreviousPerformRequestsWithTarget:self];
0

精彩评论

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