NSBlockOperation添加多个任务

 
    //创建一个队列
    NSOperationQueue *operation=[[NSOperationQueue alloc]init];

    //把任务放在NSBlockOperation里面
    NSBlockOperation *myOperation=[NSBlockOperation blockOperationWithBlock:^{
        NSData *firstData=[NSData dataWithContentsOfURL:[NSURL URLWithString:KURL1]];
     
        dispatch_async(dispatch_get_main_queue(), ^{
           
            _firstImageView.image=[UIImage imageWithData:firstData];
       });
       
    }];
  
    //把第二任务添加到操作队列
    [myOperation addExecutionBlock:^{
        NSData *secondData=[NSData dataWithContentsOfURL:[NSURL URLWithString:KURL1]];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            _secondImageView.image=[UIImage imageWithData:secondData];
        });
        
    }];
    [operation addOperation:myOperation];

 

posted @ 2015-03-29 21:55  曹县三胖暴打大猩猩  阅读(273)  评论(0编辑  收藏  举报