UITableViewCell Selected Background Color on Multiple Selection

后端 未结 14 1045
夕颜
夕颜 2020-12-08 04:26
// Doesn\'t work
cell.selectionStyle = .Blue
//Works when the selection is not multiple, if it\'s multiple with each selection the previous one disappear...
let cell         


        
14条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 04:45

    Swift 5 - This works for me:

     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
            let selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath as IndexPath)!
            selectedCell.contentView.backgroundColor = .red
        }
    
    
    
        func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
    
            let cellToDeSelect:UITableViewCell = tableView.cellForRow(at: indexPath as IndexPath)!
            cellToDeSelect.contentView.backgroundColor = .clear
        }
    

提交回复
热议问题