UITableViewCell checkmark to be toggled on and off when tapped

前端 未结 14 1478
执念已碎
执念已碎 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条回答
  •  没有蜡笔的小新
    2020-11-30 22:57

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
        if self.checkedIndex == indexPath.row{
    
        }else{
            let cell = tableView.cellForRow(at: indexPath)
            cell?.accessoryType = .checkmark
            let indexPathh = IndexPath(row: checkedIndex, section: 0)
            let UnCheckCell = tableView.cellForRow(at: indexPathh)
            UnCheckCell?.accessoryType = .none
            checkedIndex = indexPath.row
        }
    }
    

提交回复
热议问题