IOS网络第一天 - 02SDWebImage
**************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的更多相关文章
- IOS网络第一天-01基本的HTTP请求
*************************** #import "HMViewController.h" #import "MBProgressHUD+MJ.h& ...
- 【读书笔记】iOS网络-异步请求与运行循环
异步请求需要运行循环.当数据传递到服务器或是被客户端接收时,运行循环用于实现事件与委托对象之间的通信.异步请求在发出时,会在当前线程的运行循环上操作,这个实现细节是很重要的,因为在GCD块中或者是通过 ...
- ios网络学习------4 UIWebView的加载本地数据的三种方式
ios网络学习------4 UIWebView的加载本地数据的三种方式 分类: IOS2014-06-27 12:56 959人阅读 评论(0) 收藏 举报 UIWebView是IOS内置的浏览器, ...
- IOS 网络浅析-(十三 SDWebImage 实用技巧)
IOS 网络浅析-(十三 SDWebImage 实用技巧) 首先让我描述一下为了什么而产生的实用技巧.(在TableView.CollectionView中)当用户所处环境WiFi网速不够快(不能立即 ...
- 对比iOS网络组件:AFNetworking VS ASIHTTPRequest
对比iOS网络组件:AFNetworking VS ASIHTTPRequest 作者 高嘉峻 发布于 2013年2月28日 | 7 讨论 分享到:微博微信FacebookTwitter有道云笔记邮件 ...
- iOS基础 - iOS网络基础
一.网络访问的四个步骤 l 第一步:确定地址URL l 第二步:建立请求 l 第三步:建立并启动连接 l 第四步:连接完成,处理结果 备注:URL,统一资源定位符(URL,英语Uniform Reso ...
- 最简单的iOS网络请求
做iOS开发,说到网络请求,大家可能都不约而同的提到AFN,可以说大家的网络请求都是用AFN封装而成,AFN的强大易用的确很好. 但是版本升级就会出现一些问题,所以就自己基于iOS原生封装了一个网络请 ...
- iOS网络基础---iOS-Apple苹果官方文档翻译
CHENYILONG Blog iOS网络基础---iOS-Apple苹果官方文档翻译 iOS网络基础 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http: ...
- iOS网络高级编程:iPhone和iPad的企业应用开发之错误处理
本章内容 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcWluZ2h1YXdlbmthbmc=/font/5a6L5L2T/fontsize/400/fi ...
随机推荐
- poj 2774 Long Long Message 后缀数组基础题
Time Limit: 4000MS Memory Limit: 131072K Total Submissions: 24756 Accepted: 10130 Case Time Limi ...
- AFNetworking 之于 https 认证
写在开头: 本来这篇内容准备写在AFNetworking到底做了什么?(三)中的,但是因为我想在三中完结这个系列,碍于篇幅所限.并且这一块内容独立性比较强,所以单独拎出来,写成一篇. 本文从源码的角度 ...
- iOS 含有 中文的URL 转码问题
非ARC模式下: - (NSString *)encodeToPercentEscapeString: (NSString *) input { NSString *outputStr = (NSSt ...
- dotnet core 初试两个小问题解决
1. Setup has detected that visual studio 2015 update 3 may not be completely installed 在安装 DotNetCor ...
- Hadoop YARN资源隔离技术
YARN对内存资源和CPU资源采用了不同的资源隔离方案.对于内存资源,它是一种限制性资源,它的量的大小直接决定应用程序的死活,因为应用程序到达内存限制,会发生OOM,就会被杀死.CPU资源一般用Cgr ...
- mac mysql
http://blog.neten.de/posts/2014/01/27/install-mysql-using-homebrew/
- BZOJ3084 : [Algorithmic Engagements 2011]The Shortest Period
枚举答案长度$L$,设$A$和$B$分别为第一个循环节和反串的第一个循环节. 1.坏点不在$A$,那么可以暴力匹配检验. 2.坏点不在$B$,那么把串翻转后不在$A$中,转化为1. 3.坏点在$A$和 ...
- Storm命令详解
在Linux终端直接输入storm,不带任何参数信息,或者输入storm help,可以查看storm命令行客户端(Command line client)提供的帮助信息.Storm 0.9.0.1版 ...
- 【URAL】1960. Palindromes and Super Abilities
http://acm.timus.ru/problem.aspx?space=1&num=1960 题意:给一个串s,要求输出所有的s[0]~s[i],i<|s|的回文串数目.(|s|& ...
- [BZOJ2788][Poi2012]Festival
2788: [Poi2012]Festival Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 187 Solved: 91[Submit][Statu ...