打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
UITableView异步加载图片+缓存

不是arc项目,请手动添加"relese"

重新修改,加入sbjson库,刚才忘了加了!


1.将WQTableViewController.h和WQTableViewController.m拖入项目中

2.在自己的viewController中继承WQTableViewController并加入WQTableViewDelegate

例如:

#import "WQTableViewController.h"

@interfaceViewController : WQTableViewController<WQTableViewDelegate>

3.在自己的viewController.m中的- (void)viewDidLoad中配置参数如下:

wqTable=mytable ;//("mytable 为自己的table")

tableDataArray = myTableDataArray;//("myTableDataArray"为自己table显示数据的数组)

delegate=self;

4.在自己的viewController.m中加入code:

-(void)cellImageDidLoad:(NSIndexPath *)indexPath image:(UIImage *)image

{

    UITableViewCell *cell = [wqTable cellForRowAtIndexPath:indexPath];

    cell.imageView.image = image;

}

5.最后在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中图片的设置为

NSString*imageName = [[[tableDataArrayobjectAtIndex:indexPath.row] valueForKey:KidKey] stringByAppendingString:@".temp"];

NSString*imageDataPath = [NSHomeDirectory() stringByAppendingPathComponent:[@"Library/Caches/"stringByAppendingString:imageName]];

    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfFile:imageDataPath]];

    if (image) {

        cell.imageView.image = image;

    }

    else {

        cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];

//placeholder为在未加载完成加载图片时显示的默认图片

    }

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
IOS
iOS——UIView背景图片设置
iOS开发UI篇—UIScrollView控件实现图片缩放功能
详解iOS多图下载的缓存机制
iOS 8 自适应 Cell
IOS开发中@2x图片等适应不同分辨率手机
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服