I am Trying to change the background color for a tableView Cell when selected with the following code, however it does not work.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
nameTextField.text = contacts[indexPath.row].name
phoneTextField.text = contacts[indexPath.row].phone
addressTextField.text = contacts[indexPath.row].address
selectedContact = indexPath.row
let cell = tableView.dequeueReusableCell(withIdentifier: "ContactCell", for: indexPath)
let bgColorView = UIView()
bgColorView.backgroundColor = UIColor.green
cell.selectedBackgroundView = bgColorView
What is wrong with this code?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
nameTextField.text = contacts[indexPath.row].name
phoneTextField.text = contacts[indexPath.row].phone
addressTextField.text = contacts[indexPath.row].address
selectedContact = indexPath.row
let cell = tableView.dequeueReusableCell(withIdentifier: "ContactCell", for: indexPath)
let bgColorView = UIView()
bgColorView.backgroundColor = UIColor.green
cell.selectedBackgroundView = bgColorView
What is wrong with this code?