自定义NSOperation

自定义操作:

-(void)customOperation

{

    //创建队列

    NSOperationQueue *queue = [[NSOperationQueue alloc]init];

    

    //封装操作

    XMGOperation *op = [[XMGOperation alloc]init];//自定义NSOperation,执行的任务在自定义类的main方法中执行。

    

    //添加到队列

    [queue addOperation:op];

    self.queue = queue;

}

 

取消操作  [self.queue cancelAllOperations];

在自定义的XMGOperation中重写main方法,在main方法里执行需要的任务。 通过在该方法中判断

  if (self.cancelled) {

        return;

    }

判断任务是否取消。

原文地址:https://www.cnblogs.com/dashengios/p/10421297.html