I am creating an application that uses colored table view tables to categorize other cells. I do this by coloring cells with different colors using if else statements. But for some reason, when I launch the application, the more I look up and down the table view, the more other cells randomly change color. This is the code in my customTableCell class:
@IBOutlet var nameLabel: UILabel?
@IBOutlet var descriptionLabel: UILabel?
@IBOutlet var thumbnailImage: UIImageView!
func configurateTheCell(recipie: Recipie) {
self.nameLabel?.text = recipie.name
self.descriptionLabel?.text = recipie.description
self.thumbnailImage?.image = UIImage(named: recipie.thumbnails)
if nameLabel!.text == "Instrument"
{
backgroundColor = UIColor.orangeColor()
nameLabel?.textColor = UIColor.blackColor()
}
else if nameLabel!.text == "Optional addon"
{
backgroundColor = UIColor.cyanColor()
}
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if nameLabel!.text == "Instrument"
{
return 20
}
else if nameLabel!.text == "Optional addon"
{
return 20
}
else
{
return 100
}
}
and this is what the application looks like at startup:

against. when the user scrolls a bit:

also, if someone knows how, I would like the color cells to be smaller too, so that the application looks better.