我有以下方法,它基本上将图像数据数组加载到数组中:
-(void)loadImages:(NSMutableArray*)imagesURLS{
//_indexOfLastImageLoaded = 0;
[_loadedImages removeAllObjects];
_loadedImages = [[NSMutableArray alloc]init];;
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
for (int i=0; i<imagesURLS.count;i++){
NSLog(@"loading image for main image holder at index %i",i);
NSData *imgData = [NSData dataWithContentsOfURL:[imagesURLS objectAtIndex:i]];
UIImage *img = [UIImage imageWithData:imgData];
[_loadedImages addObject:img];
//_indexOfLastImageLoaded++;
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"_loadedImages download COMPLETE");
});
});
}
例如,当用户离开正在加载这些图像的视图控制器时,我希望能够停止它。最好的方法是什么?
谢谢!