【发布时间】:2011-05-15 20:23:51
【问题描述】:
我有一个 tableView,我要在顶部插入行。
在执行此操作时,我希望当前视图保持完全静止,因此只有在您向上滚动时才会显示行。
我尝试保存底层 UIScrollview 的当前位置并在插入行后重置位置,但这会导致上下抖动,尽管它最终会回到同一个位置。
有没有什么好的方法可以做到这一点?
更新:我使用的是 beginUpdate,然后是 insertRowsAtIndexPath,endUpdates。没有 reloadData 调用。
scrollToRowAtIndexPath 跳转到当前单元格的顶部(在添加行之前保存)。
我尝试过的另一种方法,以完全正确的速度结束,但有点颤抖。
save tableView currentOffset. (Underlying scrollView method)
Add rows (beginUpdates,insert...,endUpdates)
reloadData ( to force a recalulation of the scrollview size )
Recalculate the correct new offset from the bottom of the scrollview
setContentOffset (Underlying scrollview method)
问题是 reloadData 导致 scrollview/tableview 开始短暂滚动,然后 setContentOffset 将其返回到正确的位置。
有没有办法让 tableView 在不开始显示的情况下计算出它的新大小?
将整个内容包装在 beginAnimation commitAnimation 中也无济于事。
更新 2:这显然可以完成 - 当您下拉更新时,请查看官方 twitter 应用程序。
【问题讨论】:
-
只是想对没有公认的解决方案表示抱歉。我不再有权访问代码来检查任何解决方案。我很清楚的一件事是我的解决方案很糟糕,但这就是最终发布的!我希望他们现在已经改变了。
-
喂,你以后有解决办法吗?
标签: iphone uitableview uikit uiscrollview