在iOS 8自动高度的单元格内输入时,UITableView在endUpdates上跳转到顶部 [英] UITableView jumping to top on endUpdates while typing inside a cell on iOS 8 auto height
问题描述
我正在使用iOS 8自行调整单元格( tableView.rowHeight = UITableViewAutomaticDimension
和 tableView:estimatedHeightForRowAtIndexPath:
)组合。它很有效,直到我开始在单元格内输入内容。当我打字时,我正在调用 beginUpdates
/ endUpdates
对来调整我的单元格大小(文本视图随着我的增长而增长)在我删除时键入并缩小)但每次调用都会导致跳转到表视图的顶部。如果我删除 beginUpdates
/ endUpdates
对,那么它不会跳转但我的单元格不会调整大小。
I am using iOS 8 self-sizing cells (tableView.rowHeight = UITableViewAutomaticDimension
and tableView:estimatedHeightForRowAtIndexPath:
) combination. It works great until I start typing something inside a cell. When I'm typing, I'm calling beginUpdates
/endUpdates
pair to resize my cell (text view grows as I type and shrinks as I delete) but each call results in a bad jump to top of the table view. If I remove the beginUpdates
/endUpdates
pair then it doesn't jump but my cell doesn't resize as I type.
以下是该问题的演示:
如何在不跳转的情况下让我的单元格正确调整大小表格顶部的视图?我只针对iOS> = 8,所以我不需要任何iOS 7兼容性。
How can I get my cell to resize correctly as I type while not jumping to the top of the table view? I am only targeting iOS >= 8 so I don't need any kind of iOS 7 compatibility.
推荐答案
我正在实施与聊天应用程序完全相同的东西,并获得与现在相同的问题。这件事帮助了我。如果这也适合您,请告诉我。
I was implementing the exactly the same thing for chat app and getting the same issue as you are getting now. This thing helped me out. Let me know if this works for you too.
UIView.setAnimationsEnabled(false)
tableView.beginUpdates()
cell.textView.scrollRangeToVisible(NSMakeRange(cell.textView.text.characters.count-1, 0))
tableView.endUpdates()
UIView.setAnimationsEnabled(true)
tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: false)
这篇关于在iOS 8自动高度的单元格内输入时,UITableView在endUpdates上跳转到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!