iOS_文章3党库SDWebImage

1,下载的文章3党库SDWebImage代码包增加到project

2,进入project的Build Phases,将源代码包里面的所有.m文件所有加入到project

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];


















版权声明:本文博主原创文章,博客,未经同意不得转载。

posted @ 2015-09-21 17:21  mengfanrong  阅读(205)  评论(0编辑  收藏  举报