【发布时间】:2016-08-23 01:26:07
【问题描述】:
我检查了 NSBundle,但找不到 SDWebImage 保存图像的缓存。是否启用了缓存(请参见下面的代码)?根据Docs,它负责缓存管理。
如文档中所述:
只需#import UIImageView+WebCache.h 头文件,然后调用 sd_setImageWithURL:placeholderImage: 方法来自 tableView:cellForRowAtIndexPath: UITableViewDataSource 方法。 一切都会为您处理,从异步下载到缓存 管理。
#import <SDWebImage/UIImageView+WebCache.h>
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] autorelease];
}
// Here we use the new provided sd_setImageWithURL: method to load the web image
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
cell.textLabel.text = @"My Text";
return cell;
}
【问题讨论】:
标签: ios caching sdwebimage