//网络图像获取
-(void)imageDownLoadByUrlASYNC:(NSString *)url
Complete:(complete)finished{
//异步并列执行
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ UIImage *image = nil;NSURL *myUrl = [NSURL
URLWithString:url];// NSData *responseData = [NSData
dataWithContentsOfURL:myUrl];NSError *error;
NSData *responseData =
[NSData dataWithContentsOfURL:myUrl options:NSDataReadingMappedIfSafe error:&error];image = [UIImage
imageWithData:responseData];//跳回主队列执行
dispatch_async(dispatch_get_main_queue(),
^{//在主队列中进行ui操作
finished(image);
});
});
}
//接收图片的处理
UIImageView *imageView =
[imageViewArray objectAtIndex:i];UIActivityIndicatorView
*activeView = [activeViewArray objectAtIndex:i];[activeView startAnimating];
[imageView
imageDownLoadByUrlASYNC:[imageDownLoadURL objectAtIndex:i] Complete:^(UIImage *image) {if(image)
imageView.image = image;
else
{
imageView.image = [UIImage
imageNamed:@"no.jpeg"];}
[activeView
stopAnimating];}];