askaale askaale - 1 month ago 7
Swift Question

Swift TableView Prevent Button color change on selection

I am having a hard time preventing color change on my background color for my

IBAction
button when I select a row in my
tableView
. The background of my button is set to green, but when I tap the table view cell, it becomes gray. I have tried to change the color through different functions (tableView
didSelectRowAtIndexPath
etc..). Any ideas on how I would prevent the background of the button to change?

Thanks in advance!

Answer

I have faced same problem with button backgroundColor in TableView and solved it this way.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let cell = tableView.cellForRow(at: indexPath) as! CustomCell
    cell.button.backgroundColor = UIColor.greenColor()
}
Comments