Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cancel multiple delayed performSelector calls

I have to stop the call in the fenumeration.

NSTimeInterval delay = 2;
for (NSString* sentence in sentences) {
   [sentenceHandler performSelector:@selector(parseSentence:)
                         withObject:sentence
                         afterDelay:delay];
   delay += 2;
}

How to stop this call from above? I tried:

[NSObject cancelPreviousPerformRequestsWithTarget:sentenceHandler 
    selector:@selector(parseSentence) object:nil];

but there's no effect? Does it only quit one of the many calls in the loop?

like image 476
Fabian Steinhauer Avatar asked Apr 07 '11 12:04

Fabian Steinhauer


1 Answers

You have two options. You could use this which would remove all queued calls to parseSentence::

[NSObject cancelPreviousPerformRequestsWithTarget:sentenceHandler];

Or you can remove each one individually (Note the colon ":" after the method parseSentence):

[NSObject cancelPreviousPerformRequestsWithTarget:sentenceHandler
                                         selector:@selector(parseSentence:)
                                           object:sentence];
like image 159
FreeAsInBeer Avatar answered Oct 01 '22 10:10

FreeAsInBeer