如果我选择(单击)一行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