我有一个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)
Run Code Online (Sandbox Code Playgroud)
麻烦是reloadData导致scrollview/tableview开始短暂滚动,然后setContentOffset将它返回到正确的位置.
有没有办法让tableView在没有开始显示的情况下计算出它的新尺寸?
将整个事物包装在beginAnimation commitAnimation中也没有多大帮助.
更新2:这显然可以完成 - 当您下载更新时,请参阅官方Twitter应用程序.