多线程06-(sdwebimage 总结3)
2015-06-18 11:21
281 查看
2.SDWebImage 1> 常用方法 - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; 2> 内存处理:当app接收到内存警告时 /** * 当app接收到内存警告 */ - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { SDWebImageManager *mgr = [SDWebImageManager sharedManager]; // 1.取消正在下载的操作 [mgr cancelAll]; // 2.清除内存缓存 [mgr.imageCache clearMemory]; } 3> SDWebImageOptions * SDWebImageRetryFailed : 下载失败后,会自动重新下载 * SDWebImageLowPriority : 当正在进行UI交互时,自动暂停内部的一些下载操作 * SDWebImageRetryFailed | SDWebImageLowPriority : 拥有上面2个功能
// // HMAppsViewController.m // 01-cell图片下载(了解) // // Created by apple on 14-9-18. // Copyright (c) 2014年 heima. All rights reserved. // #import "HMAppsViewController.h" #import "HMApp.h" #import "UIImageView+WebCache.h" @interface HMAppsViewController () /** * 所有的应用数据 */ @property (nonatomic, strong) NSMutableArray *apps; @end @implementation HMAppsViewController #pragma mark - 懒加载 - (NSMutableArray *)apps { if (!_apps) { // 1.加载plist NSString *file = [[NSBundle mainBundle] pathForResource:@"apps" ofType:@"plist"]; NSArray *dictArray = [NSArray arrayWithContentsOfFile:file]; // 2.字典 --> 模型 NSMutableArray *appArray = [NSMutableArray array]; for (NSDictionary *dict in dictArray) { HMApp *app = [HMApp appWithDict:dict]; [appArray addObject:app]; } // 3.赋值 self.apps = appArray; // _apps = appArray; } return _apps; } #pragma mark - 初始化方法 - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.apps.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"app"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } // 取出模型 HMApp *app = self.apps[indexPath.row]; // 设置基本信息 cell.textLabel.text = app.name; cell.detailTextLabel.text = app.download; // 下载图片 NSURL *url = [NSURL URLWithString:app.icon]; UIImage *placeholder = [U 4000 IImage imageNamed:@"placeholder"]; // [cell.imageView sd_setImageWithURL:url placeholderImage:placeholder]; // [cell.imageView sd_setImageWithURL:url placeholderImage:placeholder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { // NSLog(@"----图片加载完毕---%@", image); // }]; SDWebImageOptions options = SDWebImageRetryFailed | SDWebImageLowPriority; [cell.imageView sd_setImageWithURL:url placeholderImage:placeholder options:options progress:^(NSInteger receivedSize, NSInteger expectedSize) { // 这个block可能会被调用多次 NSLog(@"下载进度:%f", (double)receivedSize / expectedSize); } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { NSLog(@"----图片加载完毕---%@", image); }]; return cell; } @end
相关文章推荐
- OSSIM下RRDTool实战
- OSSIM下RRDTool实战
- eclipse插件explorer安装使用
- 原型设计工具
- Core Java 笔记(三) - 反射
- IPV6
- iOS 中^block 示例
- 面试总结
- Android out of memory 彻底解决Android因加载多个大图引起的OutOfMemoryError,内存溢出的问题
- C# 中正确实现 IDisposable 接口
- 用户的调研
- Windows 10桌面版 Outlook/闹钟应用可交互通知
- javascript随机显示背景图片的方法
- 指数哥伦布码
- 《30天编写自己的操作系统》 关于如何让虚拟机从U盘启动
- java基础-String、基本数据类型对象包装类
- Josephus问题(约瑟夫问题)链表的实现
- block 中循环引用的问题
- Mongodb的副本、分片搭建方式
- mysql导入sql数据库提示。您可能正在上传很大的文件,请参考文档来寻找解决方法