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


















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

  • 相关阅读:
    apache solr简单搭建
    Flash学习初总结
    UWP多设备加载不同xaml布局文件
    鼠标右键多余选项删除
    用命令查看win10/win8.1等详细激活信息方法:
    win10 登陆选项 无法打开
    UWP应用开发:添加复制按钮,添加引用
    notepad++详细介绍!
    Python安装出现2503 2502 问题解决!
    Genymotion插件安装教程
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4826717.html
Copyright © 2011-2022 走看看