【发布时间】:2014-12-18 13:02:48
【问题描述】:
所以我有一个 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
【问题讨论】:
-
你解决了吗?我遇到了同样的问题,无法深入了解。
-
@David 我的解决办法是不幸地停止使用自动调整单元格大小并回到旧的
heightForRowAtIndexPath。 -
我也得出了我需要这样做的结论,但我一直无法弄清楚如何计算单元格的高度。你碰巧提到你是怎么做的吗?
标签: ios iphone uitableview swift uiscrollview