zoukankan      html  css  js  c++  java
  • 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];


















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

  • 相关阅读:
    高精度、大整数幂取模
    关于正则表达式
    003.android资源文件剖析(Resources)
    myBatis 基础测试 表关联关系配置 集合 测试
    Android应用开发学习笔记之播放音频
    移植一个开源点餐网到SAE平台上
    6.0RMB MP3所看到的……
    [读书笔记]设计原本[The Design of Design]
    递归 和 非递归 遍历二叉树
    Android应用开发学习笔记之播放视频
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4826717.html
Copyright © 2011-2022 走看看