I change the height of a UIImageView inside UITableViewCell programmatically.So when there is an image url, height is 100.0 and when image url is nil, height is 0.0 .
This is the code i use in my tableViewCell class :
func setConstraints(_height:CGFloat){
self.commentImage.addConstraint(NSLayoutConstraint(item: self.commentImage,attribute: .height,relatedBy: .equal,toItem: self.commentImage,attribute: .width,multiplier: _height / 287.0,constant: 0))
self.commentImage.updateConstraints()
self.commentImage.layoutIfNeeded()
}
if let img = comment.image {
let imgUrl = URL(string: img)
self.commentImage.sd_setImage(with: imgUrl, placeholderImage: UIImage(named: "PlaceHolder Shop"))
setConstraints(_height: 100.0)
}else {
self.commentImage.image = nil
setConstraints(_height: 0.0)
}
Now the problem is that when I scroll the tableview, some of the rows that has no image url, get the height of 100.0 for UIImageView, which leaves a blank area, And if I scroll tableView very fast, sometimes the images in rows are gone.
What should I do to solve this problem?What am I missing here?