#pragma mark-  UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
UIImage *img = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:_productDetailImageAry[indexPath.row]];
if (!img) {
img = [UIImage imageNamed:@"产品默认图"];
}
CGFloat height = img.size.height;
return (height/img.size.width)*CScreenWidth;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _productDetailImageAry.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
MDSListImageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[self confirmCell:cell atIndexPath:indexPath];
return cell;
}
- (void)confirmCell:(MDSListImageCell *)cell atIndexPath:(NSIndexPath *)indexPath{
NSString *imgUrl = _productDetailImageAry[indexPath.row];
UIImage *cachedImg = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:imgUrl];
if (!cachedImg) {
[self downloadImage:imgUrl forIndexPath:indexPath];
}else{
cell.imageShow =cachedImg;
}
}
- (void)downloadImage:(NSString *)imageURL forIndexPath:(NSIndexPath *)indexPath{
__weak typeof(self) weakSelf = self;
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:SDIMAGE_URL(imageURL)
options:
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
[[SDImageCache sharedImageCache] storeImage:image forKey:imageURL toDisk:YES];
[weakSelf performSelectorOnMainThread:@selector(reloadCellAtIndexPath:) withObject:indexPath waitUntilDone:NO]; }];
}
-(void)reloadCellAtIndexPath:(NSIndexPath *)indexPath {
[_listTableView reloadData];
}

iOS之UITableView加载网络图片cell自适应高度的更多相关文章

  1. iOS - UITableView加载网络图片 cell适应图片高度

    使用xib创建自定制cell   显示图片   创建一个继承UITableViewCell的类   勾选xib 如下是xib创建图 xib 向.h拖拽一个关联线 .h .m 2.代码创建(使用三方适配 ...

  2. ios UIImageView异步加载网络图片

    方法1:在UI线程中同步加载网络图片 UIImageView *headview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 4 ...

  3. iOS之WKWebView加载的网页自适应大小

    一,前言 有时候在WKWebView加载页面后会发现页面的字会很小, 这是因为原网页没有做手机屏幕尺寸的适配, 那么在后台不做调整的情况下我们移动端怎样来适配页面呢? 以下代码可以适配大小(原本不可以 ...

  4. ios UIImageView异步加载网络图片2

    //1. NSData dataWithContentsOfURL // [self.icon setImage:[UIImage imageWithData:[NSData dataWithCont ...

  5. iOS UItableview 镶嵌 collectionView ,cell 自适应高度动态布局

    最近在写这个功能,之前看到很多,可是需求一直没有涉及到,大致思路是有的,发现,网上的大部分都有缺陷和bug,我也是好无语啦啦啦,也不晓得是不是升级 了xcode,一样的代码,允许的效果都不一样,,,苦 ...

  6. 【iOS入门】UITableView加载图片

    学习带图片的列表 官方 LazyTableImages demo  http://download.csdn.net/detail/jlyidianyuan/5726749 分析源码是学习的好方法. ...

  7. UITableView加载几种不同的cell

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  8. 有关DTCoreText无法加载网络图片及应用问题

    至于DTCoreText是干嘛的,不清楚的同学自行网上脑补,这就不啰嗦了,只说一下其用法. 里面有三种控件供大家使用,DTAttributedTextView, DTAttributedLabel 和 ...

  9. UIImageView异步加载网络图片

    在iOS开发过程中,经常会遇到使用UIImageView展现来自网络的图片的情况,最简单的做法如下: 去下载https://github.com/rs/SDWebImage放进你的工程里,加入头文件# ...

随机推荐

  1. Windows下安装配置PLSQL

    说明:1.PLSQL Developer是远程连接Oracle数据库的一个可视化工具,并且其不是一个独立的软件,是需要依赖Oracle客户端运行的.2.本安装教程是基于本机没有安装Oracle数据库的 ...

  2. HashMap底层实现原理及面试问题

    ①HashMap的工作原理 HashMap基于hashing原理,我们通过put()和get()方法储存和获取对象.当我们将键值对传递给put()方法时,它调用键对象的hashCode()方法来计算h ...

  3. linux mysql主从复制配置

    1.设置主库master的servie-id值并且开启bin-log功能参数vi /etc/my.cnf修改my.cnf的参数:[mysqld]server-id=1 //每一个库的server-id ...

  4. IQueryable 和 IEnumerable(二)

    IQueryable 和 IEnumerable的扩展方法 一  我们从ef的DbSet<T>看起来,我们看到他继承了IQueryable<T> 和 IEnumerable&l ...

  5. 数据库MySQL--基础查询

    1.查询字段 查询表某字段:select 字段名 from 表名: 查询表内所有字段:select * from 表名: (当字段和关键字重名是用( ` )着重号区分 ) 2.查询常量值 select ...

  6. [JZOJ3303] 【集训队互测2013】城市规划

    题目 题目大意 求\(N\)个点的简单无向图的方案数(有编号). 结果对\(1004535809\)取模. 思考历程 感觉这个问题非常经典. 当时想到了一堆式子,但都觉得可能会有重和漏,于是弃掉了-- ...

  7. create table常用命令

    CREATE TABLE students( stuID INTEGER NOT NULL , stuname ) not null, sex int NOT NULL ); CREATE TABLE ...

  8. E: Sub-process /usr/bin/dpkg returned an error code (1)解决办法

    解决方法: 先将info文件夹更名 sudo mv /var/lib/dpkg/info /var/lib/dpkg/info.bk 新建一个新的info文件夹 sudo mkdir /var/lib ...

  9. System.Web.Mvc.IController.cs

    ylbtech-System.Web.Mvc.IController.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, Public ...

  10. hexo next中遇到的bug,引发出的关于jquery中click()函数和on("click",function())的区别

    个人博客:https://mmmmmm.me 源码:https://github.com/dataiyangu/dataiyangu.github.io 背景: 本人在维护博客的时候加入了aplaye ...