我目前正在我的项目中实现可扩展的 uitableviewcell。 This is my reference tutorial .
我的 View Controller 有 4 个部分,第 4 个部分(1 行)是唯一需要打开/关闭的部分。我无法获取此部分的索引路径。
代码不起作用,因为 xcode 似乎对我指的是哪个部分和行感到困惑。
这是代码(和教程里的一样)
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 2{
if dataCellExpanded {
print("111")
dataCellExpanded = false
} else {
dataCellExpanded = true
}
tableView.beginUpdates()
tableView.endUpdates()
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0{
if dataCellExpanded {
return 250
}else {
return 50
}
}
return 50
}
最佳答案
如果你只有 1 行那么你不应该检查 indexPath.row == 0
而不是 indexPath.row == 2
如果你在其他地方没有扩展行部分。如果你有,你可以检查 indexPath.section
以获取点击的部分。
关于swift - 获取具有多个部分的表中一行的索引路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48684691/