繁体   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