Swift: Change the cell's UIButton Image With tableView DidSelect method

前端 未结 3 1656
有刺的猬
有刺的猬 2020-12-07 00:26

I Have TableView with the two label and one UIButton inside the Tableview. So on DidSelect method i want to change the UIButton<

3条回答
  •  日久生厌
    2020-12-07 01:04

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
            guard let btn = (tableView.cellForItem(at: indexPath) as! yourCellName).button else {
                return
            }
            btn.setImage(UIImage(named: "yourSelectedImage name"), for: .normal)
        }
        func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
            guard let btn = (tableView.cellForItem(at: indexPath) as! yourCellName).button else {
                return
            }
            btn.setImage(UIImage(named: "yourNotSelectedImagename"), for: .normal)
        }
    

提交回复
热议问题