[英]TableView cell not resizing after changing imageView height constraint based on Image height downloaded using SDWebImage (AUTOLAYOUT)
I'm using autolayout.This is my code using it under cellForRowAtIndexPath
: 我正在使用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()
})
The cell doesn't resize. 单元格不会调整大小。 It only resizes after scrolling.
它只在滚动后调整大小。 What should I do?
我该怎么办? Since I'm using autolayout, I'm not implementing
heightForRowAtIndexPath
. 因为我正在使用autolayout,所以我没有实现
heightForRowAtIndexPath
。 I've already mentioned UITableViewAutomaticDimension
and estimatedRowHeight
. 我已经提到了
UITableViewAutomaticDimension
和estimatedRowHeight
。
I think you have to call self.view.setNeedsLayout() this will make the whole view to layout fixing the constraints 我认为你必须调用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.