簡體   English   中英

基於使用SDWebImage(AUTOLAYOUT)下載的圖像高度更改imageView高度約束后,TableView單元格未調整大小

[英]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 我已經提到了UITableViewAutomaticDimensionestimatedRowHeight

我認為你必須調用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM