[英]UITableViewCell changing height
我想在表格视图中更改触摸行的高度(因此它会扩展):
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()。 现在所选单元格的分隔符正在向下移动,但上方单元格的分隔符消失了,我仍然遇到问题
尝试重新加载该单元格
tableView.beginUpdates()
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic) //try other animations
tableView.endUpdates()
如果您不必选择单元格,那么此线程应该是答案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.