cancelAllOperations 不适用于 [NSOperationQueue mainQueue]
cancelAllOperations()
不适用于 mainQueue(cancel()
方法不会在 NSOperation
对象上调用)。我错过了什么吗? 我必须遍历所有操作并调用 cancel()
方法才能使其正常工作。
cancelAllOperations()
doesn't work on the mainQueue (the cancel()
method is not called on the NSOperation
object). Am I missing something?
I have to iterate through all operations and call the cancel()
method to get it work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还可以确认 cancelAllOperations 不适用于 [NSOperationQueue mainQueue] (至少在我的 iOS 5.0 模拟器上)。可能是故意这样设计的,因为它是一个共享实例。
我的简单解决方法就是子类 NSOperation 或 NSBlockOperation 而不覆盖任何内容,然后执行如下操作:
I can also confirm that cancelAllOperations does not work on [NSOperationQueue mainQueue] (at least on my iOS 5.0 Simulator). Might be intentionally designed like that since it is a shared instance.
My simple workaround is just to subclass NSOperation or NSBlockOperation without overriding anything and then do something like this:
是的,还可以确认它不会对操作调用取消方法,它只是设置
isCancelled = YES
我的解决方案:
[[[NSOperationQueue mainQueue] actions] makeObjectsPerformSelector:@selector(cancel)] ;
Yeah can also confirm it doesn't call cancel method on the operations, it just sets
isCancelled = YES
My solution:
[[[NSOperationQueue mainQueue] operations] makeObjectsPerformSelector:@selector(cancel)];