我正在使用自动布局。这是我在 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()
})
单元格不会调整大小。它仅在滚动后调整大小。我应该怎么办?
因为我使用的是自动布局,所以我没有实现 heightForRowAtIndexPath
。我已经提到了 UITableViewAutomaticDimension
和 estimatedRowHeight
。
最佳答案
我认为你必须调用 self.view.setNeedsLayout() 这将使整个 View 布局修复约束
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()
})
关于ios - 根据使用 SDWebImage 下载的图像高度更改 imageView 高度约束后 TableView 单元格未调整大小(AUTOLAYOUT),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37502294/