头像网址相同时 调用 SDWebImageRefreshCached 有时并不会刷新头像 代码如下
[_headImageView sd_setImageWithURL:[NSURL URLWithString:_headPic] placeholderImage:[UIImage imageNamed:@"defaultHeadPic"] options:SDWebImageRefreshCached];
用GCD替换
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0), ^{ //1
NSURL*url = [NSURLURLWithString:_headPic];
// NSURLRequestReloadIgnoringLocalAndRemoteCacheData 表示忽略本地和服务器的 缓存文件 直接从原始地址下载图片 缓存策略的一种
NSURLRequest*re = [NSURLRequestrequestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheDatatimeoutInterval:60];
NSData*received = [NSURLConnectionsendSynchronousRequest:re returningResponse:nilerror:nil];
UIImage*overlayImage = [UIImageimageWithData:received];
dispatch_async(dispatch_get_main_queue(), ^{// 2
cell.pic.image= overlayImage;// 3
});
});
//下面是 SD_WebImage 的方法(用下面的方法在我们的服务器上下载的图片有时不是最新的因此用上面的GCD 实现
//[cell.pic sd_setImageWithURL:[NSURL URLWithString:_headPic] placeholderImage:[UIImage imageNamed:@"defaultHeadPic"] options:SDWebImageRefreshCached];
网友评论