我正在使用自动布局。这是我在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
。
答案 0 :(得分:0)
我认为你必须调用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()
})