Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 841 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cancelling queued performSelector:afterDelay calls

#1
does anybody know if it is possible to cancel already queued selector events from the event stack or timer stack (or whatever mechanism it is that is utilized by the API) when you call `performSelector:withObject:afterDelay`?

I was using this event stack to alter the attributes of an image within a TabBar tab, and would sometimes queue up to 10 seconds worth of changes in one quickly executed for loop... maybe 5 milliseconds or so.

the problem arises if the user switches tabs... like say I have the image alterations queued for an image that is displayed as soon as Tab #4 is enabled, and then the user quickly switches to Tab #3 and then right back to Tab #4... this would then re-queue another 10 seconds worth of alterations while the old queue was still playing, probably around 2 or 3 seconds in to the queue if switched quick enough... but even arriving at 5 seconds in to the stream was a problem.

so I needed some way to cancel the old stack of changes before putting a new stack on...

I'm writing this query in the past tense because I already came up with an alternative solution to this problem by adding a hawk-eyed event filter on the playback function. however I am still curious if event cancellation is possible, because I have a feeling such knowledge will come in handy in the future. thank you for any assistance rendered :)

Reply

#2
[NSObject cancelPreviousPerformRequestsWithTarget:]

or

[NSObject cancelPreviousPerformRequestsWithTarget:selector:object:]

The `target` is the original object on which `performSelector:afterDelay:` was called.

For example:

// schedule the selector
[self performSelector:@selector(mySel:) withObject:nil afterDelay:5.0];
// cancel the above call (and any others on self)
[NSObject cancelPreviousPerformRequestsWithTarget:self];

See [apple docs][1], it's right at the end of the `performSelector:withObject:afterDelay:` description.


[1]:

[To see links please register here]

:
Reply

#3
In order to cancel all previous perform requests, you may use :

[NSObject cancelPreviousPerformRequestsWithTarget:self];

Reply

#4
Check the NSRunLoop docs. You want `-cancelPerformSelectorsWithTarget:`
Reply

#5
If you are looking for "performSelector" to have its matching "`cancelPreviousPerformSelector`"... it doesn't. (Ugh, Apple, why do you do that to me???)

The, er, ah, "matching" methods are:

performSelector

cancelPreviousPerformRequestsWithTarget

(Just to make it extra hard to remember, without searching the docs.)
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through