我正在使用异步任务从我的主视图控制器上的 Web 获取图像。当用户单击我的表格视图上的任何单元格时,我想暂停异步任务并转到另一个视图。我该怎么做?当用户返回主视图时,我还需要继续执行任务。我的代码
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
UIImage *imagefromWeb = [UIImage imageWithData:[NSData dataWithContentsOfURL:[IconArray objectAtIndex:indexPath.row]]];
CGSize newSize= CGSizeMake(45.0,45.0);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[imagefromWeb drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image=newImage;
[cell setNeedsLayout];
MAKE_IMAGE_CURVED(cell.imageView)
});
});