如果我在UIView的子类中这样做:
[self performSelector:@selector(doSomething) withObject:nil afterDelay:5];
然后像这样取消它(我已经尝试过两个版本):
[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self];
//[[NSRunLoop mainRunLoop] cancelPerformSelectorsWithTarget:self];
仍会调用“ doSomething”方法。我究竟做错了什么?
最佳答案
在NSObject类参考中:
cancelPreviousPerformRequestsWithTarget:selector:object:
取消先前的执行请求
注册于
performSelector:withObject:afterDelay:。
采用:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(doSomething) object:nil];
希望这可以帮助。
关于iphone - iPhone-cancelPerformSelectorWithTarget无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3971195/