scrollToRowAtIndexPath不滚动到正确的行后3/4的行 [英] scrollToRowAtIndexPath not scrolling to correct row after 3/4 of rows

查看:3293
本文介绍了scrollToRowAtIndexPath不滚动到正确的行后3/4的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有大约100行的UITableView的iPad应用程序。细胞是定制的,我实现了heightForRowAtIndexPath来告诉UITableView我的细胞有多大。

I've got an iPad app with a UITableView that has roughly 100 rows. The cells are custom, I've implemented heightForRowAtIndexPath to tell the UITableView how big my cells are.

我使用这个:

   [tableView scrollToRowAtIndexPath:indexPath 
              atScrollPosition:UITableViewScrollPositionMiddle animated:NO];

将表滚动到给定行。这对于1-75行非常合适。行76略微偏离中间,76-79稍微偏离,并且从行80开始,它不再滚动到正确的位置。它只是放在行79是最后一个可见行。在这种情况下,我仍然可以通过拖动手指来手动滚动表格;它显然还没有结束。看起来然而,在编程方式,scrollToRowAtIndexPath 认为它已经到达表的结尾之前它实际上有。我会期望这种行为在表的结尾,而不是在3/4的行。

to scroll the table to a given row. This works perfectly for row 1-75. Row 76 is slightly off the middle, 76-79 are slightly more off, and as of row 80, it no longer scrolls to the correct position at all. It just stays put with row 79 being the last visible row. I can still manually scroll the table by dragging my finger when this happens; it's observably not yet at the end. It seems however that programmatically, scrollToRowAtIndexPath thinks it has reached the end of the table before it actually has. I would expect this behaviour at the end of the table, not at 3/4 of the rows.

我很难调试这里发生的事情;我会感谢任何指针,帮助我找出为什么表认为它已经在结束时,我调用scrollToRowAtIndexPath。

I am struggling to debug what is happening here; I would appreciate any pointers that help me find out why the table is thinking it is already at the end when I call scrollToRowAtIndexPath.

推荐答案

我注意到这个问题被查看了很多,所以也许更多的人遇到这个问题。最终我发现,这不是tableview的问题。它被定位在一个视图中,当旋转设备或代码调整其大小时行为不当。 tableview实际上超出了它所在的视图的边界,所以输出看起来很奇怪,但如果你认为tableview结束超出了屏幕的边界,它实际上是有意义的。

I noticed this question is viewed quite a lot so maybe more people run into this issue. Eventually I found out that it wasn't the tableview's problem. It was positioned in a view that was misbehaving when rotating the device or resizing it from code. The tableview actually extended beyond the boundary of the view it was in, so the output looked weird but if you consider that the tableview ended beyond the boundary of the screen, it actually made sense.

我解决了它通过清理视图层次结构,并确保调整大小和旋转工作正常。

I solved it by cleaning up the view hierarchy and making sure that resizing and rotating worked properly.

这篇关于scrollToRowAtIndexPath不滚动到正确的行后3/4的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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