SDWebImage下载图片
来源:互联网 发布:淘宝店铺出租价格 编辑:程序博客网 时间:2024/06/06 01:09
<pre name="code" class="objc">// 显示图片// [cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:[UIImage imageNamed:@"user_default"]]; // 另外下载图像的方法 [cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:[UIImage imageNamed:@"user_default"] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { // receivedSize 已经接受到的大小 // expectedSize 期望的大小,总大小 float progress = (float)receivedSize/expectedSize; NSLog(@"下载进度 %f", progress); } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { NSLog(@"%@", [NSThread currentThread]); }];
//// ViewController.m////#import "ViewController.h"#import "CZApp.h"#import "UIImageView+WebCache.h"@interface ViewController ()// plist文件数据的容器@property(nonatomic,strong)NSArray *appList;@end@implementation ViewController// 懒加载- (NSArray *)appList{ if (_appList == nil) { NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"apps.plist" ofType:nil]]; // 字典转模型 NSMutableArray *arrayM = [NSMutableArray array]; for (NSDictionary *dict in dictArray) { CZApp *app = [CZApp appWithDict:dict]; [arrayM addObject:app]; } _appList = arrayM; } return _appList;}#pragma mark - 数据源方法- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.appList.count;}/** 问题1: 如果网络比较慢,会比较卡 解决办法:用异步下载 */// cell里面的imageView子控件也是懒加载。- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *ID = @"AppCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; // 给cell设置数据 CZApp *app = self.appList[indexPath.row]; cell.textLabel.text = app.name; cell.detailTextLabel.text = app.download; // 显示图片// [cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:[UIImage imageNamed:@"user_default"]]; // 另外下载图像的方法 [cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon] placeholderImage:[UIImage imageNamed:@"user_default"] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) { // receivedSize 已经接受到的大小 // expectedSize 期望的大小,总大小 float progress = (float)receivedSize/expectedSize; NSLog(@"下载进度 %f", progress); } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { NSLog(@"%@", [NSThread currentThread]); }]; return cell;}@end
3 0
- SDWebImage下载图片
- SDWebImage下载图片
- 利用sdwebImage下载图片
- SDWebImage-SDWebImageDownloader下载图片
- SDWebImage下载图片的方法
- SDWebImage异步下载图片方法
- 网络多线程下载图片(SDWebImage)
- 使用SDWebImage直接下载图片
- 用SDWebImage开源库异步下载图片
- SDWebImage类实现图片的下载
- SDWebImage下载和缓存图片(UIImge)
- 网络多线程-下载图片(不用SDWebImage框架)
- 多线程:下载图片(不用SDWebImage)
- iOS 下载缓存网络图片 SDWebImage
- 用SDWebImage下载图片、缓存图片到UIImage
- tableView异步下载图片/SDWebImage图片缓存原理
- SDWebImage下载
- iOS: (库) 图片异步下载/缓存-SDWebImage的使用
- BOX2D 自然的旋转到一个指定角度
- 由C++的泛型句柄类思考OpenCV的Ptr模板类
- Java泛型
- 正则表达式
- Android 使用fastjson找不到fastjson包问题的解决方法
- SDWebImage下载图片
- java多线程采集+线程同步
- BOX2D 自然的旋转到一个指定角度
- 重新加载tableView指定section的数据
- 带坑水题--第六届省赛A
- 读写Excel -- ExcelToolUtil
- 【Spring学习】IoC与DI
- 《Linux4.0设备驱动开发详解》笔记--第七章:Linux设备中的并发控制
- 1分钟快速生成用于网页内容提取的xslt