标签:ios sdwebimage
1,将下载好的第3方类库SDWebImage源码包加入到工程
2,进入工程的Build Phases,将源码包里面的所有.m文件全部添加到工程
3,导入第3方类库依赖的两个系统自带的框架:MapKit.framework、ImageIO.framework
4,添加第3方类库的主头文件"UIImageView+WebCache.h"
代码使用片段:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"Beyond";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
// 如果池中没取到,则重新生成一个cell
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
// 设置cell中独一无二的内容
Status *s = _statuses[indexPath.row];
cell.textLabel.text = s.text;
cell.detailTextLabel.text = s.user.screenName;
cell.textLabel.numberOfLines = 0;
// 重要~使用第3方框架 SDWebImage,缓存策略:失败再请求,磁盘缓存,scrollView滚动时暂停下载图片
[cell.imageView setImageWithURL:[NSURL URLWithString:s.user.profileImageUrl] placeholderImage:[UIImage imageNamed:@"avatar_default.png"] options:SDWebImageLowPriority | SDWebImageRefreshCached | SDWebImageRetryFailed];
// 返回cell
return cell;
}关键代码,缓存策略:
失败再请求:SDWebImageRetryFailed
磁盘缓存:SDWebImageRefreshCached
scrollView滚动时暂停下载图片:SDWebImageLowPriority
[cell.imageViewsetImageWithURL:[NSURLURLWithString:s.user.profileImageUrl]placeholderImage:[UIImageimageNamed:@"avatar_default.png"]options:SDWebImageLowPriority |SDWebImageRefreshCached |SDWebImageRetryFailed];
iOS_第3方类库SDWebImage简单使用,布布扣,bubuko.com
标签:ios sdwebimage
原文地址:http://blog.csdn.net/pre_eminent/article/details/38404679