iPhone - cancelPerformSelectorWithTarget 不起作用

标签 iphone ipad selector request-cancelling

如果我在 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/

相关文章:

ios - Swift 默认参数和选择器语法

ios - % 字符未显示在 iOS 通知中

iphone - MBProgressHUD 未显示

ios - CALayer.contents 无法在 AVMutableComposition 中正确呈现

android - 平板电脑操作系统的低级文本引擎

iphone - UIActionSheet 在 UIPopoverController 中有 20 多个选项

css - 使用 CSS 选择没有类和 ID 的元素?

css - 选择外部元素 CSS

iphone - UITableView 和使用 NSURLconnection 的异步加载

iphone - html5 视频不能在 ipad 模拟器中播放?