ios - TableView didSelect 行问题
问题描述
所以问题是当一个单元格被点击时,显示所需的数据,当再次点击同一个单元格时(再次显示所需的数据。)
But when one cell is selected and we again select other cell (then the data is been shown of second tapped cell but the first one is not deselected).
我该如何处理这个问题?
var selectedIndex = -1
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
UIView.animate(withDuration: 1) {
self.labelViewHeightConstraint.constant = 60
self.labelLeadingConstraint.constant = 136
self.view.layoutIfNeeded()
}
let cell = tableView.cellForRow(at: indexPath) as! CustomCell
if(selectedIndex == indexPath.row) {
selectedIndex = -1
print("deselect")
UIView.animate(withDuration: 0.4) {
cell.secondView.isHidden = true
cell.firstView.backgroundColor = UIColor(red: 0.8588, green: 0.84705, blue: 0.8745, alpha: 1.0)
}
} else {
cell.secondView.isHidden = false
}
self.expandTableView.beginUpdates()
//self.expandTableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic )
self.expandTableView.endUpdates()
}
解决方案
推荐阅读
- python - 使用 ortools 最大化旅行商问题
- python - 获取隐藏层自动编码器
- python - 如何计算高于/低于阈值的时间序列中的连续周期?
- python - 在 if 循环中首先编写 99% 的情况是否有任何效率提升?
- java - 如何支持我不拥有源代码的类的 jpa 数据库序列化?
- plc - TwinCAT 3 Ads 函数 InvokeRpcMethod() 不起作用,并给出符号“Value is null”的错误
- sql - 我想在不使用 DISTINCT 的情况下每个 subject_id 只显示一行。不知道该怎么做
- swift - 如何在 iOS 应用程序中不断地从 Firebase 读取更新的值
- python - 使用元类动态扩展 django 模型
- c++ - 将自签名证书添加到共享对象 C++ 库