askaale askaale - 1 year ago 84
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

button when I select a row in my
. 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
etc..). Any ideas on how I would prevent the background of the button to change?

Thanks in advance!

Answer Source

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()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download