【发布时间】:2016-01-26 16:21:06
【问题描述】:
我正面临这个问题,我一直在试图弄清楚如何解决它,但没有成功。
我有一个表格视图,其中的单元格包含一个我仍然不知道高度的图像。我为 imageView 的高度约束创建了一个出口,并且我正在使用 PinRemoteImage 异步下载图像(我也可以使用SDWebImage,但我认为它在 iOS 9 中存在问题)。块内部是我为高度约束分配新常量的地方,然后我进行布局更新。
单元格永远不会更新,我能正确看到图像的唯一方法是向下滚动然后向上滚动(当 tableview 重新绘制单元格时)
__weak typeof(UITableView*) weakTable = tableView;
__weak typeof(NSIndexPath*) index = indexPath;
[cell.commentImageView pin_setImageFromURL:[[CTImageHelper sharedInstance] resizedImageURLConverterFromStringWithPrefix:comment.image.completePath andOptions:optionsString] completion:^(PINRemoteImageManagerResult *result) {
CommentTableViewCell *cellToUpdate = [weakTable cellForRowAtIndexPath:index];
cellToUpdate.heightSize = [NSNumber numberWithFloat:result.image.size.height/2];
cellToUpdate.commentImageViewHeightConstraint.constant = result.image.size.height/2;
[cellToUpdate setNeedsLayout];
}];
这是自动设置表格视图行高的代码
self.postTableView.estimatedRowHeight = 244.0;
self.postTableView.rowHeight = UITableViewAutomaticDimension;
关于我做错了什么有什么想法吗?谢谢!
【问题讨论】:
-
不要对 imageview 进行高度限制。下载图像时更新此单元格。细胞应该会自动生长
标签: ios objective-c uitableview autolayout objective-c-blocks