如何暂停一个NSOperation

我怎么才能暂停一个NSOperation?在NSOPeration的文档里没有找到任何相关的东西
还有,在一个Queue里,如果暂停了一个Operation会阻塞么?还是会被滞后?

明显的有个cancel方法

直接

[operation cancel];

cancel
Advises the operation object that it should stop executing its task.

– (void)cancel
Discussion
This method does not force your operation code to stop. Instead, it updates the object’s internal flags to reflect the change in state. If the operation has already finished executing, this method has no effect. Canceling an operation that is currently in an operation queue, but not yet executing, makes it possible to remove the operation from the queue sooner than usual.

In OS X v10.6 and later, if an operation is in a queue but waiting on unfinished dependent operations, those operations are subsequently ignored. Because it is already cancelled, this behavior allows the operation queue to call the operation’s start method sooner and clear the object out of the queue. If you cancel an operation that is not in a queue, this method immediately marks the object as finished. In each case, marking the object as ready or finished results in the generation of the appropriate KVO notifications.

In versions of OS X prior to 10.6, an operation object remains in the queue until all of its dependencies are removed through the normal processes. Thus, the operation must wait until all of its dependent operations finish executing or are themselves cancelled and have their start method called.

For more information on what you must do in your operation objects to support cancellation, see “Responding to the Cancel Command.”

Availability
Available in iOS 2.0 and later.
See Also
– isCancelled
Related Sample Code
MVCNetworking
Declared In
NSOperation.h

  • ios端上传流,如果服务端没有接收流,直接响应,ios端会超时,怎么解决呢?
  • Cordova插件开发时无法导入阿里百川的iOS SDK
  • 如何动态调整tableView的section间距的方法 ?
  • iOS heightForRowAtIndexPath会执行6次呢
  • MLEmojiLabel 加载长文字时卡顿
  • 目前来看,html app 转成 native app 用什么技术或者工具比较好?
  • iOS 关于storyboard 设置textfield的属性疑问
  • Reachability 添加网络监控通知后,断网、联网都不会接收到通知,求指教
  • ionic写的内容,欢迎页是ios原生写的,但是调用H5写的input type=file,xcode控制台就报错?
  • iOS tableview 编辑模式下删除状态:标记区域的背景色能否修改
  • IOS开发小问题-解释下一段代码