取消排队的performSelector:afterDelay调用 [英] cancelling queued performSelector:afterDelay calls

查看:210
本文介绍了取消排队的performSelector:afterDelay调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在调用performSelector:withObject:afterDelay时是否可以从事件堆栈或计时器堆栈(或API使用的任何机制)中取消已排队的选择器事件吗?

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?

我正在使用此事件堆栈来更改TabBar选项卡中图像的属性,有时在一次快速执行的循环中可能会排队长达10秒钟的更改,价值可能长达10秒钟,大约5毫秒左右.

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.

如果用户切换选项卡,就会出现问题...就像说我让启用了选项卡#4的图像排队等待更改的图像更改,然后用户迅速切换到选项卡#3,然后向右切换返回标签4 ...这会在旧队列仍在播放时重新排队另外10秒钟的变更时间,如果切换得足够快的话,大约2到3秒钟会进入队列...甚至达到5秒钟.流中的秒数是个问题.

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 :)

推荐答案

[NSObject cancelPreviousPerformRequestsWithTarget:]

[NSObject cancelPreviousPerformRequestsWithTarget:selector:object:]

target是调用performSelector:afterDelay:的原始对象.

例如:

// 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, it's right at the end of the performSelector:withObject:afterDelay: description.

这篇关于取消排队的performSelector:afterDelay调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆