IPhone - cancelPerformSelectorWithTarget not working

If I do this in a subclass of UIView:

[self performSelector:@selector(doSomething) withObject:nil afterDelay:5];

Then undo it like this (I tried both versions):

 [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
 //[[NSRunLoop mainRunLoop] cancelPerformSelectorsWithTarget:self];

The doSomething method is still called. What am I doing wrong?

+3
source share
1 answer

In the NSObject class reference:

cancelPreviousPerformRequestsWithTarget: selector: object:

Cancels the execution of queries previously registered by performSelector: withObject: afterDelay :.

Using:

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doSomething) object:nil];

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1770361/


All Articles