UITableView - Multiple selection AND single selection

前端 未结 4 1537
半阙折子戏
半阙折子戏 2020-12-31 14:15

I have 2 sections in my UITableView.
I want the first section to allow multiple cell selection and the second section to allow only single selection.
I tried some co

4条回答
  •  我在风中等你
    2020-12-31 14:58

    You can simply try this. This solution works for me perfectly. Give it a try maybe worked for others...

    Swift-4

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.section == 0 {
            if let cell = tableView.cellForRow(at: indexPath) {
                cell.accessoryType = .checkmark
            }
        }
        else {
            if let cell = tableView.cellForRow(at: indexPath) {
                cell.accessoryType = .checkmark
            }
        }
    }
    
    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        if indexPath.section == 1 {
            if let cell = tableView.cellForRow(at: indexPath as IndexPath) {
                cell.accessoryType = .none
            }
        }
    }
    

提交回复
热议问题