objective-c - 执行cancelPreviousPerformRequestsWithTarget :selector:object: for all objects

标签 objective-c cocoa cocoa-touch grand-central-dispatch

我在不同的对象上安排不同的选择器

[self performSelector:@selector(doSmth) withObject:objectA afterDelay:1];
[self performSelector:@selector(doSmth) withObject:objectB afterDelay:1];
[self performSelector:@selector(doSmthElse) withObject:objectA afterDelay:1];

我想取消所有“doSmth”,该怎么做?不知道传递的对象

这将取消一切

[NSObject cancelPreviousPerformRequestsWithTarget:self];

这不会取消任何内容(因为对象不匹配)

[NSObject cancelPreviousPerformRequestsWithTarget:object 
    selector:@selector(doSmth) object:nil];

即使我会异常(exception)的行为(当传递 nil 时取消任何对象,但这不会发生)

最佳答案

无法获取待处理 performSelector 请求的列表,因此您需要维护传递给 performSelector 的参数列表,以便可以稍后取消它们。

关于objective-c - 执行cancelPreviousPerformRequestsWithTarget :selector:object: for all objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28367134/

相关文章:

objective-c - 无法使用 GNUStep 编译 objective-c 应用程序

ios - 继承自 UITextField 的类导致无法获取内容?

objective-c - NSDictionary 的描述 - 为什么有些键名带有引号?

iphone - 无法设置对象 - 只读属性或未找到 setter

ios - 如果我插入此函数 -imageFromCurrentFramebufferWithOrientation - (GPUImageLookupFilter),我会收到错误消息

iphone - 将许多 subview 添加到 View Controller 默认 View 是否会使我的应用程序变慢?

iOS 应用程序在下载非常大的文件时耗尽内存

ios - 禁用拖动超过 UIWebView/UIScrollView 的顶部( "Pull to refresh"手势)

xcode - 使用 Interface Builder 设置由 NSPopupButton 显示的默认项目

cocoa - 使用中断输入端点使用 IOKit 获取回调