SDWebImage的图片缓存周期是多长 : 1个星期
ZYXApp.h
ZYXApp.m
AppDelegate.m
#import "AppDelegate.h"
#import "SDWebImageManager.h"
@implementation AppDelegate
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application{
// 清除内存缓存
[[SDWebImageManager sharedManager].imageCache clearMemory];
// 取消所有下载
[[SDWebImageManager sharedManager] cancelAll];
}
@end
ViewController.m
#import "ViewController.h"
#import "ZYXApp.h"
#import "UIImageView+WebCache.h"
@interface ViewController ()
/** 所有数据 */
@property (nonatomic, strong) NSArray *apps;
@end
@implementation ViewController
- (NSArray *)apps
{
if (!_apps) {
NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"apps.plist" ofType:nil]];
NSMutableArray *appArray = [NSMutableArray array];
for (NSDictionary *dict in dictArray) {
[appArray addObject:[ZYXApp appWithDict:dict]];
}
_apps = appArray;
}
return _apps;
}
#pragma mark - 数据源方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (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 == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
ZYXApp *app = self.apps[indexPath.row];
cell.textLabel.text = app.name;
cell.detailTextLabel.text = app.download;
/*
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon]
placeholderImage:[UIImage imageNamed:@"placeholder"]];
*/
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:app.icon]
placeholderImage:[UIImage imageNamed:@"placeholder"]
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// expectedSize: 图片的总字节数
// receivedSize: 已经接收的图片字节数
NSLog(@"下载进度:%f", 1.0 * receivedSize / expectedSize);
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
NSLog(@"下载完图片");
NSLog(@"SDWebImage下载完图片返回的imageURL %@",imageURL);
}];
// SDWebImage的图片缓存周期是多长 : 1个星期
return cell;
}
@end
//2016-08-10 15:32:41.709 SDWebImage[65507:991542] 下载完图片
//2016-08-10 15:32:41.710 SDWebImage[65507:991542] SDWebImage下载完图片返回的imageURL http://p18.qhimg.com/dr/48_48_/t012fea7312194537c2.png
返回图片在远程服务器的URL地址
[[SDWebImageManager sharedManager] downloadImageWithURL:nil
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
}];