iOS 8 自动单元格高度 - 无法滚动到最后一行 [英] iOS 8 Auto cell height - Can't scroll to last row

查看:26
本文介绍了iOS 8 自动单元格高度 - 无法滚动到最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 iOS 8 新的自适应单元格.从视觉上看它效果很好 - 每个单元格都有合适的大小.但是,如果我尝试滚动到最后一行,表格视图似乎不知道它的正确大小.这是一个错误还是有修复方法?

I am using iOS 8 new self-sizing cells. Visually it works good - each cell gets its right size. However, if I try to scroll to the last row, the table view doesn't seem to know its right size. Is this a bug or is there a fix for that?

使用这个项目 - TableViewCellWithAutoLayoutiOS8(引用自 this SO answer),我按预期获得了自动调整大小的单元格.

Using this project - TableViewCellWithAutoLayoutiOS8 (referenced from this SO answer), I got the auto-resizing cells as expected.

但是,如果我调用 scrollToRowAtIndexPath 函数,如下所示:

However, if I am calling the scrollToRowAtIndexPath function, like this:

tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: model.dataArray.count - 1, inSection: 0), atScrollPosition: .Bottom, animated: true)

没有到达最后一行 - 它只能让我走到一半.

I do not get to the last row - It only gets me around halfway there.

即使尝试使用像这样的低级函数:

Even by trying to use a lower level function like this:

tableView.setContentOffset(CGPointMake(0, tableView.contentSize.height - tableView.frame.size.height), animated: true)

结果不如预期,不会走到最后.如果我多次单击它或稍等片刻,它最终会到达正确的位置.似乎 tableView.contentSize.height 设置不正确,所以 iOS不知道"最后一个单元格在哪里.

The result is not as expected, it won't get to the end. If I click it a lot of times or wait a few moments, eventually it will get to the right place. It seems the tableView.contentSize.height is not set correctly, so the iOS "doesn't know" where that last cell is.

非常感谢您的帮助.

谢谢

推荐答案

更新:2015 年 6 月 24 日

从 iOS 9.0 SDK 开始,Apple 已经解决了大部分这些错误.从 iOS 9 beta 2 开始,所有问题都已修复,包括滚动到顶部和没有动画的表格视图底部,并在表格视图中间滚动时调用 reloadData.

Apple has addressed most of these bugs as of the iOS 9.0 SDK. All of the issues are fixed as of iOS 9 beta 2, including scrolling to the top & bottom of the table view without animation, and calling reloadData while scrolled in the middle of the table view.

以下是尚未修复的剩余问题:

Here are the remaining issues that have not been fixed yet:

  1. 当使用较大的估计行高时,滚动到带有动画的最后一行会导致表格视图单元格消失.
  2. 当使用较小的估计行高时,滚动到带有动画的最后一行会导致表格视图过早完成滚动,从而在可见区域下方留下一些单元格(最后一行仍然在屏幕外).

已针对这些与滚动动画相关的问题提交了新的错误报告 (rdar://21539211).

A new bug report (rdar://21539211) has been filed for these issues relating to scrolling with animation.

原答案

这是 Apple 的表视图行高估计错误,自从 iOS 7 中首次引入此功能以来,它就一直存在.我曾直接与 Apple UIKit 工程师和开发人员就这个问题进行过合作——他们已经承认这是一个错误,但没有任何可靠的解决方法(除了禁用行高估计),并且似乎对修复它并不特别感兴趣.

This is an Apple bug with the table view row height estimation, and it has existed since this functionality first was introduced in iOS 7. I have worked directly with Apple UIKit engineers and developer evangelists on this issue -- they have acknowledged that it is a bug, but do not have any reliable workaround (short of disabling row height estimation), and did not seem particularly interested in fixing it.

请注意,该错误以其他方式表现出来,例如在部分或完全向下滚动时调用 reloadData 时表格视图单元格消失(例如 contentOffset.y大于 0).

Note that the bug manifests itself in other ways, such as disappearing table view cells when you call reloadData while scrolled partially or fully down (e.g. contentOffset.y is significantly greater than 0).

显然,对于 iOS 8 自动调整单元格大小,行高估计至关重要,因此 Apple 确实需要尽快解决这个问题.

Clearly, with iOS 8 self sizing cells, row height estimation is critically important, so Apple really needs to address this ASAP.

我于 2013 年 10 月 21 日将此问题作为 Radar #15283329 提交回来.请提交重复的错误报告,以便 Apple 优先修复.

I filed this issue back on Oct 21 2013 as Radar #15283329. Please do file duplicate bug reports so that Apple prioritizes a fix.

您可以附上这个简单的示例项目来演示该问题.它直接基于 Apple 自己的示例代码.

You can attach this simple sample project to demonstrate the issue. It is based directly on Apple's own sample code.

这篇关于iOS 8 自动单元格高度 - 无法滚动到最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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