【发布时间】:2010-10-19 17:53:13
【问题描述】:
如果我在 UIView 的子类中这样做:
[self performSelector:@selector(doSomething) withObject:nil afterDelay:5];
然后像这样取消它(两个版本我都试过了):
[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
//[[NSRunLoop mainRunLoop] cancelPerformSelectorsWithTarget:self];
“doSomething”方法仍然被调用。我做错了什么?
【问题讨论】:
-
+1 我想我最近也注意到了这一点;我无法让它工作,所以我最终使用了不重复的
NSTimer。 :P -
但这不一定与 NSTimer 相关。它只是取消一个请求......
-
你确定这两种方法在同一个线程上运行吗?因为如果他们不这样做,那么他们会针对不同的运行循环。
-
@sol 我知道;我是说我的
cancelPerformSelector也无法正常工作,所以我使用了非重复计时器,我可以在需要时使用invalidate。 -
@Dave - 我明白了。不是一个糟糕的解决方法。可能必须自己做。
标签: iphone ipad selector request-cancelling