[英]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.