![](/img/trans.png)
[英]How to update tableview cell height after image downloaded and height constraint changed swift?
[英]TableView cell not resizing after changing imageView height constraint based on Image height downloaded using SDWebImage (AUTOLAYOUT)
我正在使用autolayout。这是我在cellForRowAtIndexPath
下使用它的代码:
cell.chatImage.sd_setImageWithURL(NSURL(string: newsFeed.postImage!), placeholderImage: UIImage(named: "default_profile"), completed: { (image, error, cacheType, imageURL) -> Void in
let height = ((image?.size.height)! / (image?.size.width)!) * (tableView.bounds.width - 16)
cell.chatImageHeight.constant = height
self.view.layoutIfNeeded()
})
单元格不会调整大小。 它只在滚动后调整大小。 我该怎么办? 因为我正在使用autolayout,所以我没有实现heightForRowAtIndexPath
。 我已经提到了UITableViewAutomaticDimension
和estimatedRowHeight
。
我认为你必须调用self.view.setNeedsLayout()这将使整个视图布局修复约束
cell.chatImage.sd_setImageWithURL(NSURL(string: newsFeed.postImage!), placeholderImage: UIImage(named: "default_profile"), completed: { (image, error, cacheType, imageURL) -> Void in
let height = ((image?.size.height)! / (image?.size.width)!) * (tableView.bounds.width - 16)
cell.chatImageHeight.constant = height
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.