ios - 更改单元格高度后 UITableView 在滚动时跳动

标签 ios iphone uitableview swift uiscrollview

所以我有一个 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/

相关文章:

objective-c - 转到另一个函数中的标签

iphone - 动态生成解密 key 而不是硬编码字符串文字? ( objective-C/iPhone)

iphone - 当 iOS 版本 < 4.* 时执行函数

ios - 什么是重新加载 UITableView 数据的更可靠方法?

objective-c - 将元素放入部分数组的大条件,更好的方法吗? - Objective-C

ios - 如何快速解决日历问题? (很高兴即使在 Objective-c 中也能看到)

ios - 模态转场链

iphone - Xcode 4.2 (雪豹) 和 iOS 5.1

ios - Splunk 薄荷 : Failed to archive dSYMs for "MyApp" to "/tmp/splunk-mint-dsyms"

ios - 通知 UITableViewCell tableview 正在滚动的最佳方法是什么