自下而上的UITableView具有不同的项目高度滚动到结尾 [英] Bottom-up UITableView with different item height scroll to end

查看:76
本文介绍了自下而上的UITableView具有不同的项目高度滚动到结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不同项目高度的UITableView。
一开始,用户应该看到最后的项目(位于列表的末尾),并且应该能够手动滚动到顶部。



为了到达列表的末尾,我在调用 [tableView reloadData]之后在主线程上使用 [tableView scrollToRowAtIndexPath:lastIndexPath atScrollPositionBottom animated:NO] 关于后台进程。
为了加快速度并达到真正的目的,我使用 estimatedHeightForRowAtIndexPath 并返回前8项(CGFloat)500 和其他项目(CGFloat)100
使用 estimatedHeightForRowAtIndexPath 为列表中的每个项目避免调用 heightForRowAtIndexPath (它可能很长使用iOS 8(iPhone 4S,5S,6),一切正常,但iOS 7(iPhone 4S)只需 heightForRowAtIndexPath 调用但不是 cellForRowAtIndexPath ,因此在我开始滚动之前没有显示任何项目。
返回(CGFloat)100 为每个 estimatedHeightForRowAtIndexPath -call避免这种情况,但它不会滚动到这个列表真正的结尾和iOS 8 iPhone 4S版本相比很慢。



有什么建议吗?

解决方案

我们最终更好地实现了 estimatedHeightForRowAtIndexPath
我们用一些简单的计算计算前50个项目的估计高度,因此我们得到的值非常接近实际高度。
对于其他项目,我们从第一次计算中返回平均值。


I have a UITableView with different item height. At the beginning the user should see the last items (that are at the end of the list) and should be able to scroll manually to the top.

To get to the end of the list I use [tableView scrollToRowAtIndexPath:lastIndexPath atScrollPositionBottom animated:NO] on the main thread after I called [tableView reloadData] on a background process. To speed it up and to get to the real end I use estimatedHeightForRowAtIndexPath and I return for the first 8 items (CGFloat)500 and for the other items (CGFloat)100. Using estimatedHeightForRowAtIndexPath avoids the call for heightForRowAtIndexPath for every item in the list (it could be a very long list).

With iOS 8 (iPhone 4S, 5S, 6) everything works fine, but with iOS 7 (iPhone 4S) just heightForRowAtIndexPath get called but not cellForRowAtIndexPath, so there is no item displayed until I start to scroll. Returning (CGFloat)100 for every estimatedHeightForRowAtIndexPath-call avoids this, but it doesn't scroll to the real end of the list and compaired to the iOS 8 iPhone 4S version it is pretty slow.

Any suggestions?

解决方案

We ended up with a better implementation of estimatedHeightForRowAtIndexPath. There we calculate with some simple calculations a better estimated height for the first 50 items, so we get values pretty close to the real height. For the other items we return an average from the first calculations.

这篇关于自下而上的UITableView具有不同的项目高度滚动到结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆