Patricia
Patricia

Reputation: 289

performSelector and matching cancelPreviousPerformRequestWithTarget

If I start something using this:

> [self performSelector:@selector(runThis:) 
>    withObject:thisObject  
>    afterDelay:5.0];

Which 1 should I later use to cancel it, avoiding "runThis:" from ever running?

1> [NSObject cancelPreviousPerformRequestsWithTarget:self];

or

2> [NSObject cancelPreviousPerformRequestsWithTarget:self 
2>    selector:@selector(runThis:) 
2>    object:nil];

Not even sure what the difference really is between 1 and 2.

Is #1 canceling ANY/ALL my performSelector's, regardless of their name?

And #2 canceling only one, specifically "runThis:"?

(What if I had 3 different performSelector running "runThis:"? How would I specify which one to cancel... using #1 or #2?)

#1 seems to correctly cancel things.

#2 doesn't seem to cancel anything.... ever.

Does it matter that I pass thisObject when starting... and nil when canceling?

Upvotes: 0

Views: 137

Answers (1)

Wevah
Wevah

Reputation: 28242

IIRC either one is fine; the second just gives you finer-grained control.

For #2 you'd have to pass in an object that returns YES for -isEqual:. nil does not mean "anything" for that method, unlike the NSNotification stuff.

Upvotes: 1

Related Questions