更新我的UITableView的高度有一个延迟

时间:2016-12-19 19:27:15

标签: ios swift uitableview scroll

我想更新UITableView中的底部单元格,并向下滚动视图,以便可以看到整个新单元格。 (单元格的旧内容大约有50像素高;新内容大约有100像素高。桌子的内容比它的边界视图高得多。)但是当我这样做时:

tableView.beginUpdates()
tableView.reloadRows(at: [myIndexPath], with: .none)
tableView.endUpdates()
tableView.setContentOffset(
    CGPoint(x: 0, y: tableView.contentSize.height - tableView.bounds.size.height),
    animated: true)
然后,相反,我向上滚动到我的tableView顶部之上。问题是,在endUpdates被调用的那一刻,tableView.contentSize.height突然缩小了几百个像素,因此它比边界视图小。我不明白为什么会这样。

我发现如果我在setContentOffset附近添加约500毫秒或更长的延迟,那么事情就会正常运行,但我不想使用延迟。

DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
    self.tableView.setContentOffset(CGPoint(x: 0, y: self.tableView.contentSize.height - self.tableView.bounds.size.height),
                                    animated: true)
}

我已尝试按https://stackoverflow.com/a/35228192/548862使用CATransation,但这对问题没有任何影响。

我有一个tableView estimatedHeightForRowAt方法来估计行高(来自一组常量),但我不知道这怎么可能搞砸我。

我做错了什么?

0 个答案:

没有答案