iOS学习笔记-124.多线程23——多图下载3_第三种实现方式(使用SDWebImage)
来源:互联网 发布:uk域名注册要求 编辑:程序博客网 时间:2024/06/11 00:11
- 多线程23多图下载3_第三种实现方式使用SDWebImage
- 一说明
- 二代码
- 三图示
多线程23——多图下载3_第三种实现方式(使用SDWebImage)
一、说明
前面的例子中,我们已经是实现了我们想要的功能。现在我们使用第三方框架 SDWebImage 来实现一把。这会变得很简单的,我们使用到的方法是在这个框架中的UIImageView+WebCache.h
分类中。我们使用的方法如下
/* 第一个参数:下载图片的url地址 第二个参数:占位图片 第三个参数:progress 进度回调 receivedSize:已经下载的数据大小 expectedSize:要下载图片的总大小 第四个参数: image:要下载的图片 error:错误信息 cacheType:缓存类型 imageURL:图片url */- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
SDWebImage 下载地址 https://github.com/rs/SDWebImage
二、代码
//// ViewController.m// 03_UIview86多线程_多图下载//// Created by 杞文明 on 17/9/6.// Copyright © 2017年 杞文明. All rights reserved.//#import "ViewController.h"#import "QWMAppItem.h"#import "UIImageView+WebCache.h"@interface ViewController ()/** tableView的数据源 */@property (nonatomic, strong) NSArray *apps;@end@implementation ViewController-(NSArray*)apps{ if(_apps==nil){ //字典数据 NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"apps.plist" ofType:nil]]; //字典数据转模型数据 NSMutableArray *arrM = [NSMutableArray array]; for (NSDictionary *dict in array) { [arrM addObject:[QWMAppItem appWitdDict:dict]]; } _apps = arrM; } return _apps;}/*组数*/-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;}/*每组的行数*/-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.apps.count;}/*每个cell*/-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString* identifier = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; //获取数据 QWMAppItem *appItem = self.apps[indexPath.row]; cell.textLabel.text = appItem.name; cell.detailTextLabel.text = appItem.download; [self handle3:cell withItem:appItem]; return cell;}/*图片的第三种种处理方式,使用SDWebImage*/-(UITableViewCell*)handle3:(UITableViewCell*)cell withItem:(QWMAppItem*)appItem{ /* 第一个参数:下载图片的url地址 第二个参数:占位图片 第三个参数:progress 进度回调 receivedSize:已经下载的数据大小 expectedSize:要下载图片的总大小 第四个参数: image:要下载的图片 error:错误信息 cacheType:缓存类型 imageURL:图片url */ [cell.imageView sd_setImageWithURL:[NSURL URLWithString:appItem.icon] placeholderImage:[UIImage imageNamed:@"image1"] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { NSLog(@"%f",1.0 * receivedSize / expectedSize); } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { NSLog(@"%zd",cacheType); }]; return cell;}@end
三、图示
阅读全文
0 0
- iOS学习笔记-124.多线程23——多图下载3_第三种实现方式(使用SDWebImage)
- iOS学习笔记-131.多线程24——多图下载4_第四种实现方式(缓存使用NSCache)
- iOS学习笔记-123.多线程22——多图下载2_第二种实现方式(三级缓存)
- iOS学习笔记-122.多线程21——多图下载1_第一种实现方式(不靠谱)
- ios第三方开源框架学习——SDWebImage的使用
- Android学习笔记---java实现多线程下载器,30_多线程下载原理介绍和使用
- 【我的Java笔记】多线程_多线程实现的第三种方式(线程池)
- iOS第三方学习1-SDWebImage学习和使用
- 多线程:实现下载图片(使用 SDwebImage框架)
- iOS UITableViewCell 多线程 网络+沙盒的图片加载以及第三方框架SDWebImage方式加载
- IOS学习——SDWebImage配置及使用
- IOS学习之——SDWebImage的使用
- ios学习路线—iOS高级(SDWebImage)
- android学习笔记---31_多线程断点下载器,下载原理实现
- iOS之多线程——单例模式、NSOperation、多图下载、SDWebImage
- 【我的Java笔记】多线程_使用匿名内部类的方式实现多线程
- iOS 第三方框架SDWebImage学习
- iOS第三方类库之-SDWebImage使用
- Filter(过滤器)与Interceptor(拦截器)的区别
- Android启动界面先白屏或者黑屏然后才出现画面的解决办法
- Linux下安装Redis
- 建造者设计模式
- Linux:进程控制
- iOS学习笔记-124.多线程23——多图下载3_第三种实现方式(使用SDWebImage)
- 迭代器模式+代理模式和适配器模式的简述
- 爬格子呀4-3
- centos6.5下oracle11g开机自动启动方法二
- POJ-3090
- 第一次写博客
- Spring Boot(Web)初探四( 异常处理与使用)
- HDU-1171
- MySQL 表字段唯一性约束设置方法unique