cancelPreviousPerformRequest 与 cancelAllOperations
我现在都用,但我不确定哪个更好。到底有什么区别?我知道的模糊问题。为WWDC做准备
i use now both but i'm not sure which is better. what is exactly the difference? fuzzy question i know. preparing for wwdc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
向操作队列发送
cancelAllOperations
消息会取消该队列中的所有操作(即,它告诉操作取消),而cancelPreviousPerformRequestsWithTarget:
告诉目标对象取消之前被告知要执行的所有延迟执行的操作。这里没有“更好”,只有“更好”。这两种方法没有可比性。一取消 NSOperations;另一个取消延迟执行的请求。您使用哪种取消完全取决于您是否创建了 NSOperation 并将其放入 NSOperationQueue 或发送了延迟执行请求。
Sending a
cancelAllOperations
message to an operation queue cancels all the operations in that queue (that is, it tells the operations to cancel), whereascancelPreviousPerformRequestsWithTarget:
tells the target object to cancel all delayed performs it had previously been told to do.There is no “better” here; the two methods are incomparable. One cancels NSOperations; the other cancels delayed-perform requests. Which cancellation you use depends entirely on whether you made an NSOperation and put it an NSOperationQueue or sent a delayed-perform request.