UITableViewCell checkmark to be toggled on and off when tapped

前端 未结 14 1442
执念已碎
执念已碎 2020-11-30 22:25

I\'m working on a tableview

I want to be able to tap on each cell and when tapped, it displays a checkmark on the cell

Now I have some code that makes this w

14条回答
  •  -上瘾入骨i
    2020-11-30 23:00

    Updated In swift 4.2 Every New selection Remove previous Check mark

       func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(self.coloursArray[indexPath.row])
    
         self.tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
    }
    
    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        self.tableView.cellForRow(at: indexPath)?.accessoryType = .none
    }
    

提交回复
热议问题