如果我選擇(單擊)一行TableView,它應該添加圖像說我選擇了這個特定的項目。它工作正常!雙擊UITableView單元格應該轉到之前的狀態
我的問題是:如果用戶想從該選定的項目後退。 如果我點擊同一行,它應該取消選擇該單元格並隱藏該圖像。
我想的是:
func tableView (_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath) as! leistungCell
// Configure the cell...
let tableData = self.tableData[indexPath.row]
cell.leistungLbl.text = tableData["leistung_info"] as? String
//space between Rows
cell.contentView.backgroundColor = colorLightGray
cell.contentView.layer.borderColor = UIColor.white.cgColor
//space between Rows
cell.contentView.layer.borderWidth = 3.0
cell.contentView.layer.cornerRadius = 8
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
cell?.imageView?.image = UIImage(named: "check.png")
let value = Info["leistung_info"] as! String
}
func tableView(_ tableView: UITableView, didDeSelectRowAt indexPath: IndexPath){
let cell = tableView.cellForRow(at: indexPath)
cell?.imageView?.image = nil
}
面臨什麼問題? – KKRocks
@KKRocks當我再次單擊相同的單元格時,我之前選擇的圖像將不會移動它將仍然可見。我希望該圖像能夠隱藏在該單元格中。 –
你需要在單元格之後重新加載單元格?.imageView?.image = nil。 – KKRocks