【发布时间】:2017-11-01 04:30:26
【问题描述】:
我有一个带有自定义单元格的表格视图。下图显示了我的 tableview 单元格的视图层次结构。
向 tableview 添加行时,我使用以下代码隐藏了“检查图像”图像视图。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "accountCell", for: indexPath) as! AccountsTableViewCell
cell.checkImage.isHidden = true
return cell
}
当点击一行时,我将再次显示 imageview。下面是代码
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: "accountCell", for: indexPath) as! AccountsTableViewCell
cell.checkImage.isHidden = false
}
但问题是当我点击一行时没有任何反应。系统执行cell.checkImage.isHidden = false 代码行,但没有出现图像视图。它仍然是隐藏的。有人可以告诉我我在这里做错了什么吗?
【问题讨论】:
-
点击该行后请重新加载您的tableview
-
你不能那样做。您需要在某处更新选中/未选中状态(我建议使用
Set<IndexPath>),然后在cellForRowAt中检查 - 在didSelectRowAt中,您在Set中切换选中/未选中状态,然后重新加载受影响的细胞。 -
@Nazmul Hasan 重新加载 tableview 对我不起作用
-
@udi 重新加载表格视图的位置
-
@Paulw11 你能解释一下吗?
标签: ios swift uitableview uistackview