Ios 基于使用SDWebImage下载的图像高度更改imageView高度约束后,TableView单元格未调整大小(自动布局)

Ios 基于使用SDWebImage下载的图像高度更改imageView高度约束后,TableView单元格未调整大小(自动布局),ios,swift,autolayout,tableview,sdwebimage,Ios,Swift,Autolayout,Tableview,Sdwebimage,我正在使用自动布局。这是我在cellforrowatinexpath下使用它的代码: cell.chatImage.sd_setImageWithURL(NSURL(string: newsFeed.postImage!), placeholderImage: UIImage(named: "default_profile"), completed: { (image, error, cacheType, imageURL) -> Void in let

我正在使用自动布局。这是我在
cellforrowatinexpath
下使用它的代码:

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,所以我没有实现
heightforrowatinexpath
。我已经提到了
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()

            })

我认为您必须调用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()

            })

等等,那么您是否使用uitableviewautomaticdimension?我不确定你在哪里提到过它。@user3353890我已经在视图中提到过它了。只有在我尝试更新块内的约束时才会出现问题。等等,那么您是否使用uitableviewautomaticdimension?我不确定你在哪里提到过它。@user3353890我已经在视图中提到过它了。只有当我尝试更新block内的约束时,问题才会出现。mmm,您是否可以增加estimatedRowHeight或尝试此操作,这应该会起作用------------------------------------cell.chatImageHeight.constant=height UIView.animateWithDuration(0.3,animations:cell.contentView.layoutIfNeeded)tableView?.BeginUpdate()tableView?.endUpdates()我尝试了tableView.BeginUpdate和endUpdates,但这不是一种正确的方法,应用程序最终会崩溃,因为它在indexPath的行的单元格中被反复调用。有什么消息吗?我也面临着同样的问题:/mm,你能增加估计高度吗?或者试试这个方法,应该可以------------------------------------cell.chatmageheight.constant=height UIView.animateWithDuration(0.3,animations:cell.contentView.layoutifneed)tableView?.beginUpdates()tableView?.endUpdates()我尝试过tableview.BeginUpdate和EndUpdate,但这不是一种正确的方法,应用程序最终会崩溃,因为它在indexPath的单元格中被一次又一次地调用。有什么消息吗?我面临着同样的问题:/