【发布时间】:2016-03-15 19:41:19
【问题描述】:
我想改变表格视图中被触摸行的高度(所以它会扩展):
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomTableViewCell
if let currentSelection = self.currentSelection {
if currentSelection == indexPath {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
self.currentSelection = nil
tableView.beginUpdates()
tableView.endUpdates()
setupAnimation(cell, hide: true) //Custom animation inside the cell
}
} else {
self.currentSelection = indexPath
tableView.beginUpdates()
tableView.endUpdates()
setupAnimation(cell, hide: false) //Custom animation inside the cell
}
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if let currentSelection = self.currentSelection {
if indexPath == currentSelection {
return 80.0
}
}
return 50.0
}
这是有效的 - 当我点击该行时高度变为 80.0,当我再次点击它时又回到 50.0。问题是我的分离器没有移动。
它不仅不动,而且当我点击单元格时:
- 高度扩大 ->
- 分接的单元格分隔符保持在同一个位置 ->
- 上面单元格的分隔符消失了
我做错了什么或者我在这里遗漏了什么?
编辑
我试图覆盖 layoutSubviews 方法并忘记了 - 我没有在其中调用 super.layoutSubviews()。现在所选单元格的分隔符随之向下移动,但我仍然遇到上方单元格的分隔符消失的问题
【问题讨论】:
标签: ios swift uitableview