iOS之UITableView加载网络图片cell自适应高度
#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自适应高度的更多相关文章
- iOS - UITableView加载网络图片 cell适应图片高度
使用xib创建自定制cell 显示图片 创建一个继承UITableViewCell的类 勾选xib 如下是xib创建图 xib 向.h拖拽一个关联线 .h .m 2.代码创建(使用三方适配 ...
- ios UIImageView异步加载网络图片
方法1:在UI线程中同步加载网络图片 UIImageView *headview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 4 ...
- iOS之WKWebView加载的网页自适应大小
一,前言 有时候在WKWebView加载页面后会发现页面的字会很小, 这是因为原网页没有做手机屏幕尺寸的适配, 那么在后台不做调整的情况下我们移动端怎样来适配页面呢? 以下代码可以适配大小(原本不可以 ...
- ios UIImageView异步加载网络图片2
//1. NSData dataWithContentsOfURL // [self.icon setImage:[UIImage imageWithData:[NSData dataWithCont ...
- iOS UItableview 镶嵌 collectionView ,cell 自适应高度动态布局
最近在写这个功能,之前看到很多,可是需求一直没有涉及到,大致思路是有的,发现,网上的大部分都有缺陷和bug,我也是好无语啦啦啦,也不晓得是不是升级 了xcode,一样的代码,允许的效果都不一样,,,苦 ...
- 【iOS入门】UITableView加载图片
学习带图片的列表 官方 LazyTableImages demo http://download.csdn.net/detail/jlyidianyuan/5726749 分析源码是学习的好方法. ...
- UITableView加载几种不同的cell
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- 有关DTCoreText无法加载网络图片及应用问题
至于DTCoreText是干嘛的,不清楚的同学自行网上脑补,这就不啰嗦了,只说一下其用法. 里面有三种控件供大家使用,DTAttributedTextView, DTAttributedLabel 和 ...
- UIImageView异步加载网络图片
在iOS开发过程中,经常会遇到使用UIImageView展现来自网络的图片的情况,最简单的做法如下: 去下载https://github.com/rs/SDWebImage放进你的工程里,加入头文件# ...
随机推荐
- Python从入门到精通视频(全60集)✍✍✍
Python从入门到精通视频(全60集) 整个课程都看完了,这个课程的分享可以往下看,下面有链接,之前做java开发也做了一些年头,也分享下自己看这个视频的感受,单论单个知识点课程本身没问题,大家看 ...
- jenkins深入浅出
安装: 1. 从官网上下载新版本的Jenkins,https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/2.89.4/jenkins.war ...
- ios position:fixed 上滑下拉抖动
ios position:fixed 上滑下拉抖动 最近呢遇到一个ios的兼容问题,界面是需要一个头底部的固定的效果,用的position:fixed定位布局,写完测试发现安卓手机正常的,按时ios上 ...
- javascript面向对象编程笔记(函数之闭包)
3 函数 3.5 闭包(closures) 3.5.1 作用域链 与很多程序设计语言不同,javascript不存在大括号级的作用域,但它有函数作用域,即在函数内定义的变量在函数外是不可见的.但如果该 ...
- Winform打包工具SetupFactory 9 的使用 (转)
写了个WinForm的小程序..以前没打过包..只是直接把Bin里的东西复制出来使用..自己使用是足够.但是发给别人毕竟不太好看(不牛逼)..所以就想着打包.. Vs2012自带的有打包的功能..相信 ...
- try-with-resources with JDBC
I realize this was long ago answered but want to suggest an additional approach that avoids the nest ...
- MySQL数据库之DQL(数据查询语言)
1.MySQL之DQL查询AS CONCAT LIKE的使用 (1)select 列名1,列名2,...... from 表名 [where 条件] 查询所有字段用*,不带where条件的话,就会把表 ...
- python库之mlxtend
一.安装 conda install mlxtend --channel conda-forge 具体请看参考文献一 二.入门例子 请看参考文献2上github的举例 参考文献 http://rasb ...
- Java 学习 时间格式化(SimpleDateFormat)与历法类(Calendar)用法详解
基于Android一些时间创建的基本概念 获取当前时间 方式一: Date date = new Date(); Log.e(TAG, "当前时间="+date); 结果: E/T ...
- CF 540D Bad Luck Island
一看就是DP题(很水的一道紫题) 设\(dp[i][j][k]\)为留下\(i\)个\(r\)族的人,死去\(j\)个\(s\)族的人,死去\(k\)个\(p\)族的人的概率(跟其他的题解有点差别,但 ...