I'm working on a project and I have a problem with UITableViewCells, they are having a strange behaviour when I load the viewcontroller and then when I scroll.
First of all when I load the viewcontroller I see this :
And then when I scroll down, and up I see this (that it's what I want) :
Any idea of what's going wrong?? Here it's a part of the code
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.row {
case 0: //HEADER IMAGE
return 200.0
case 1: //VAMONOS BUTTON
return 195.0
case 2:
if(more) { //WITH SCALES
if(flightScales.count == 0) {
return 165.0
}
else {
return CGFloat(flightScales.count * 205) + 110.0
}
}
else { //WITHOUT SCALES
return 165.0
}
case 3:
if(accomodationMore) { //7LINE DESCRIPTION
return 435.0
}
else { //2LINE DESCRIPTION
return 180.0
}
default:
return 0.0
}
}
And the image load :
if let image = selectedFlight.image {
let requestUrl = url + "api/vuelo/imagen/" + image
headerCell.destinationImage.sd_setImage(with: URL(string: requestUrl), placeholderImage:UIImage(named: "icon-placeholder"))
}
else {
headerCell.destinationImage.image = UIImage(named: "icon-placeholder")
}
headerCell.initialize(destinationLabel: selectedFlight.title!, countryLabel: selectedFlight.desc!)
Try this:
image.contentMode = .aspectFit //or .aspectFill
image.cliptToBounds = true