**************SDWebImage加载图片

#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 = [UIImage 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);
// }];
//SDWebImageRetryFailed 尝试重复下载
//SDWebImageLowPriority 交互不下载
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

***************HMAppDelegate.m

#import "SDWebImageManager.h"

/**
* 当app接收到内存警告
*/
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
SDWebImageManager *mgr = [SDWebImageManager sharedManager]; // 1.取消正在下载的操作
[mgr cancelAll]; // 2.清除内存缓存
[mgr.imageCache clearMemory];
}

IOS网络第一天 - 02SDWebImage的更多相关文章

  1. IOS网络第一天-01基本的HTTP请求

    *************************** #import "HMViewController.h" #import "MBProgressHUD+MJ.h& ...

  2. 【读书笔记】iOS网络-异步请求与运行循环

    异步请求需要运行循环.当数据传递到服务器或是被客户端接收时,运行循环用于实现事件与委托对象之间的通信.异步请求在发出时,会在当前线程的运行循环上操作,这个实现细节是很重要的,因为在GCD块中或者是通过 ...

  3. ios网络学习------4 UIWebView的加载本地数据的三种方式

    ios网络学习------4 UIWebView的加载本地数据的三种方式 分类: IOS2014-06-27 12:56 959人阅读 评论(0) 收藏 举报 UIWebView是IOS内置的浏览器, ...

  4. IOS 网络浅析-(十三 SDWebImage 实用技巧)

    IOS 网络浅析-(十三 SDWebImage 实用技巧) 首先让我描述一下为了什么而产生的实用技巧.(在TableView.CollectionView中)当用户所处环境WiFi网速不够快(不能立即 ...

  5. 对比iOS网络组件:AFNetworking VS ASIHTTPRequest

    对比iOS网络组件:AFNetworking VS ASIHTTPRequest 作者 高嘉峻 发布于 2013年2月28日 | 7 讨论 分享到:微博微信FacebookTwitter有道云笔记邮件 ...

  6. iOS基础 - iOS网络基础

    一.网络访问的四个步骤 l 第一步:确定地址URL l 第二步:建立请求 l 第三步:建立并启动连接 l 第四步:连接完成,处理结果 备注:URL,统一资源定位符(URL,英语Uniform Reso ...

  7. 最简单的iOS网络请求

    做iOS开发,说到网络请求,大家可能都不约而同的提到AFN,可以说大家的网络请求都是用AFN封装而成,AFN的强大易用的确很好. 但是版本升级就会出现一些问题,所以就自己基于iOS原生封装了一个网络请 ...

  8. iOS网络基础---iOS-Apple苹果官方文档翻译

    CHENYILONG Blog iOS网络基础---iOS-Apple苹果官方文档翻译 iOS网络基础 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http: ...

  9. iOS网络高级编程:iPhone和iPad的企业应用开发之错误处理

    本章内容 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWluZ2h1YXdlbmthbmc=/font/5a6L5L2T/fontsize/400/fi ...

随机推荐

  1. 《DSP using MATLAB》示例Example4.6

    用到的z变换的性质: 继续解题: 上代码: b = [0,0,0, 0.25, -0.5, 0.0625]; a = [1, -1, 0.75, -0.25, 0.0625]; % polynomia ...

  2. 服装PDA软件|服装销售开单PDA管理软件|服装PDA管理系统|服装PDA点货系统|服装移动POS系统

    浩瀚软件为了更好服务于广大批发客户群体进行销售.盘点.调拨配送等.深圳浩瀚软件推出基于无线网络版移动PDA销售开单系统.该系统支持无线3G.WIFI.GPRS系统,用户可以手持PDA在无线网络连接状态 ...

  3. java发送短信--httpclient方式

    最近头让我写个发送短信的java程序检测BI系统,检查数据库是否有异常发送,有则发送短信到头的手机里.这里我直说httpclient方式的get请求方式,并且已经有方式的短信的接口了,所以只要再加上参 ...

  4. ashx 文件 与js文件数据交互

    //js代码 //城市下拉列表             $("#selPro").change(function() {                 var option = ...

  5. ural 1073. Square Country

    1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square ...

  6. 如何查看项目svn路径

    1.选择项目根目录---->鼠标右键---->属性---->版本控制(Subversion) 如图:

  7. HDU 2855 (矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2855 题目大意:求$S(n)=\sum_{k=0}^{n}C_{n}^{k}Fibonacci(k)$ ...

  8. 在Web应用中接入微信支付的流程之极简清晰版 (转)

    在Web应用中接入微信支付的流程之极简清晰版 背景: 在Web应用中接入微信支付,我以为只是调用几个API稍作调试即可. 没想到微信的API和官方文档里隐坑无数,致我抱着怀疑人生的心情悲愤踩遍了丫们布 ...

  9. ACM: hdu 2647 Reward -拓扑排序

    hdu 2647 Reward Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Des ...

  10. [杂谈] My Wikipedia

    // 此博文为迁移而来,写于2015年6月8日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w3de.html