cancelPreviousPerformRequestsWithTarget not cancelling an outstanding performSelector:withDelay

Your perform doesn't match your cancel. In the perform you're passing self as the object:

[self performSelector:@selector(showNavigationBar) withObject:self afterDelay:0.2]; 

In the cancel you're passing nil as the object:

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

They don't match, so the delayed perform should not be canceled.


In the documentation of that + (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector:(SEL)aSelector object:(id)anArgument method there is this sentence :

This method removes perform requests only in the current run loop, not all run loops.

If I'm interpreting it correctly it would mean that you need to cancel your action in the same run loop that you launched it. Which is clearly not what you want to do.

A way to go around this would be to have a flag that showNavigationBar would have to check to see if it should proceed or abort.


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

That worked for me ;)

Tags:

Ios