UITableView scrollToRowAtIndexPath在iOS 7上使用estimatedRowHeight滚动到错误的偏移量 [英] UITableView scrollToRowAtIndexPath scrolls to wrong offset with estimatedRowHeight on iOS 7

查看:423
本文介绍了UITableView scrollToRowAtIndexPath在iOS 7上使用estimatedRowHeight滚动到错误的偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS 7中UITableView的 estimatedRowHeight 方法,该方法非常适合快速加载具有5000行可变高度的UITableView。

I am using the estimatedRowHeight method from UITableView in iOS 7, which works perfectly for fast loading of a UITableView with 5000 rows of variable heights.

我的UITableView由50个部分组成。每个部分有100行,高度可变。
一开始我使用 estimatedRowHeight 进行快速加载,但之后我调用 scrollToRowAtIndexPath 我的UITableView滚动到错误的偏移量。我可以理解为什么会这样,因为它有一个 estimatedRowHeight ,直到我滚动整个表并在 heightForRowAtIndexPath 委托方法。

My UITableView consists of 50 sections. Every section has 100 rows, of variable height. At the start I use estimatedRowHeight for fast-loading, but after that when I call scrollToRowAtIndexPath, my UITableView scrolls to the wrong offset. I can understand why this is, because it has an estimatedRowHeight until I scroll the entire table and the proper cell heights are set in the heightForRowAtIndexPath delegate method.

任何解决方案?

推荐答案

不幸的是,在这么低的值的代码中使用 estimatedRowHeight 时,会出现此问题。当您 scrollToRowAtIndexPath 时,它不会主动计算正确的大小。根本原因是,如果你从第1节滚动到第2节,它可以实时计算正确的位置和单元格的 estimatedRowHeight ,如果它是一个相对较新的设备。任何较旧的设备都会被瘫痪,例如,如果你必须处理5000个单元,那么即使是任何新设备也是如此。

Unfortunately this issue is to be expected when using estimatedRowHeight in your code with such a low value. When you scrollToRowAtIndexPath it does not actively calculating the correct size as you go. The underlying cause is, if you scrolled from Section 1 to Section 2, it could feasibly calculate the correct position on the fly and the estimatedRowHeight of the cells if it was a relatively new device. Any older devices would be brought to their knees, and even any new ones would be as well if you had to process 5000 cells, for example.

可能解决方案你的问题可能是增加 estimatedRowHeight 常量,这样设备就不需要做太多的工作。

A maybe-solution to your problem could be to increase the estimatedRowHeight constant so the device doesn't have to do as much work.

这篇关于UITableView scrollToRowAtIndexPath在iOS 7上使用estimatedRowHeight滚动到错误的偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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