这个方法太好用了,先记下来吧: 转载
http://code4app.com/ios/%E5%9B%BE%E7%89%87%E4%B8%8B%E8%BD%BD%E5%92%8C%E4%BF%9D%E5%AD%98/508bacee6803fa9b09000000
#pragma mark - 方法二
void UIImageFromURL( NSURL * URL,void (^imageBlock)(UIImage * image),void (^errorBlock)(void) )
{
dispatch_async( dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT,0 ), ^(void)
{
NSData * data = [[[NSDataalloc] initWithContentsOfURL:URL]autorelease];
UIImage * image = [[[UIImagealloc] initWithData:data] autorelease];
dispatch_async( dispatch_get_main_queue(), ^(void){
if( image != nil )
{
imageBlock( image );
} else {
errorBlock();
}
});
});
}
NSString *url = pDetail.chProimg;
UIImageFromURL( [NSURLURLWithString:url], ^( UIImage * image )
{
cell.cusDetailImagView.image=image;
}, ^(void){
NSLog(@"error!");
});