How to deselect a selected UITableView cell?

前端 未结 24 3171
一整个雨季
一整个雨季 2020-12-07 10:10

I am working on a project on which I have to preselect a particular cell.

I can preselect a cell using -willDisplayCell, but I can\'t deselect it when t

24条回答
  •  借酒劲吻你
    2020-12-07 10:13

    This is a solution for Swift 4

     in tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
    

    just add

    tableView.deselectRow(at: indexPath, animated: true)
    

    it works like a charm

    example:

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            tableView.deselectRow(at: indexPath, animated: true)
    //some code
    }
    

提交回复
热议问题