Can I get a list of selectors delayed with performSelector:withObject:afterDelay:?
Asked Answered
M

1

6

I would like to be able to cancel delayed selectors individually. I can do his with [NSObject cancelPreviousPerformRequestsWithTarget...] but need all the method parameters to do this. At the point where I want to cancel, I don't have them.

Is there a way to get the list of selectors that are delayed together with the parameters used to delay the selectors?

The workaround is to just keep track of the parameters, of course. Or to use GCD and make my selectors (now blocks) check to see whether they should immediately return.

Mothering answered 15/2, 2011 at 16:48 Comment(0)
P
0

not directly. an easy way to accomplish this is would use NSOperation - then just hold references to the operations you may need to cancel in the future.

Puett answered 15/2, 2011 at 16:51 Comment(2)
Forgot to menton: the code is driving part of the interface, so I have to keep it on the main thread. That's why I didn't throw NSOperation into the mix.Mothering
hmmm... seems like you'll have to write something to accomplish this =\ in addition to the options you've mentioned in the OP, you could register with the main run loop (you may have to go to the CF APIs) and then use NSInvocations for the message queue. alternatively you may be able to create a wrapper type to group invocations, then use cancelPreviousPerformRequestsWithTarget without the unknown parameters. finally, these messages could invoke via a custom type which implements isEqual:. then you can use a customized implementation of isEqual to identify what messages to cancel.Puett

© 2022 - 2024 — McMap. All rights reserved.