How to deselect a selected UITableView cell?

前端 未结 24 3170
一整个雨季
一整个雨季 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:23

    Swift 3

    I've run into this as well - when you navigate or unwind back to the table view it usually doesn't deselect the previously selected row for you. I put this code in the table view controller & it works well:

    override func viewDidAppear(_ animated: Bool) {
        if let lastSelectedRow = tableView.indexPathForSelectedRow {
            tableView.deselectRow(at: lastSelectedRow, animated: true)
        }
    }
    

提交回复
热议问题