所以我有一个 tableView,我想在点击时更改单元格的高度。好吧,实际上,我正在用更大的电池替换它。 点击时,我会调用:
tableView.beginUpdates()
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
tableView.endUpdate()
然后我修改我的 cellForRowAtIndexPath
以返回正确的新单元格和高度。通过覆盖单元格实现中的 sizeThatFits
自动计算单元格的高度:
override func sizeThatFits(size: CGSize) -> CGSize {
return CGSizeMake(size.width, myHeight)
}
奇怪的是,在我这样做之后,向下滚动没问题,但是当我向上滚动时,表格每秒跳跃 5 个像素左右,直到到达顶部。在我到达桌面顶部后,问题就消失了,并且没有任何方向的跳跃。知道为什么会这样吗?我想这与取代其他单元格的新单元格高度有关,但我不明白为什么 tableView 没有处理这个问题。感谢您的帮助!
谢谢!
编辑:从 cellForRowAtIndexPath 添加代码:
if self.openedCellIndex != nil && self.openedCellIndex == indexPath {
cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as ListCell
(cell as ListCell).updateWithDetailView(dayViewController!.view)
} else {
cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as ListCell
(cell as ListCell).updateWithData(eventDay: store.events![indexPath.row], reminderDay: store.reminders![indexPath.row])
}
return cell
最佳答案
您应该包括您的 cellForRow 和 heightForRow 代码,但我会盲目地尝试一下。
当在 cellForRow 中点击一个单元格时,您应该存储该单元格的索引,然后重新加载数据或 just that cell .然后在 heightForRow 中使用 if(yourTappedCell){return preferredHeight;}
关于ios - 更改单元格高度后 UITableView 在滚动时跳动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26518306/