如果我在 UIView 的子类中执行此操作:
[self performSelector:@selector(doSomething) withObject:nil afterDelay:5];
然后像这样取消它(我已经尝试了两个版本):
[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
//[[NSRunLoop mainRunLoop] cancelPerformSelectorsWithTarget:self];
“doSomething”方法仍然会被调用。我做错了什么?
最佳答案
在 NSObject 类引用中:
cancelPreviousPerformRequestsWithTarget:selector:object:
Cancels perform requests previously registered with performSelector:withObject:afterDelay:.
用途:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doSomething) object:nil];
希望这有帮助。
关于iPhone - cancelPerformSelectorWithTarget 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3971195/