我有一个 TableView,我使用委托方法 tableView:heightForRowAtIndexPath:
指定每个单元格的高度.
I have a TableView and I specify the height for each cell using the delegate method tableView:heightForRowAtIndexPath:
.
当我旋转视图时,我得到了这个我不太理解的错误.
When I rotate the view I get this error that I don't quite understand.
它不能满足下面的约束并打破它继续.
It can't satisfy the constraint below and breaks it to continue.
"<_UIScrollViewAutomaticContentSizeConstraint:0x8e8d040 UITableView:0x9423400.contentHeight{id: 213} == -1568.000000>"
有谁知道发生了什么以及我为什么要打破这个限制?
Does anyone know what is happening and why I'm breaking this constraint?
更新:这个问题在 iOS 8 中不再相关,它增加了对自调整单元格的支持.不过,它仍然适用于 iOS 7.
UPDATE: This issue is no longer relevant in iOS 8, which adds support for self-sizing cells. It is still relevant for iOS 7 however.
原始答案(iOS 7):
Greg 的回答肯定对我有用 - 我需要调试我的 tableView:estimatedHeightForRowAtIndexPath: 方法.我做了一些调试和一些快速实验,以下是我学到的一些东西:
Greg's answer definitely worked for me - I needed to debug my tableView:estimatedHeightForRowAtIndexPath: method. I did some debugging and some quick experiments and here are some things I learned:
不要在估计的 row 方法中使用 UITableViewAutomaticDimension.此常量用于页眉和页脚方法.我想我在阅读文档时没有给予足够的关注 :) 更新:UITableViewAutomaticDimension 现在可用于 iOS 8 中的行高,这是自调整单元格功能的一部分.
Don't use UITableViewAutomaticDimension in the estimated row methods. This constant is for the header and footer methods. I guess I wasn't paying enough attention when I read the documentation :) UPDATE: UITableViewAutomaticDimension can now be used for row heights in iOS 8, part of the self-sizing cells functionality.
估计行高为 1.0 会导致异常:NSInternalInconsistencyException",原因:'table view row height must not be negative...'"估计小于 1.0 也会产生奇怪的结果.
Estimating row height of 1.0 results in an exception: "NSInternalInconsistencyException', reason: 'table view row height must not be negative...'" Estimating less than 1.0 has strange results as well.
在 2.0 和实际之间进行估算可以正常工作,没有任何例外(尽管出于优化原因,2.0 可能是一个不好的选择 - 您希望尽可能接近实际).
Estimating between 2.0 and the actual works just fine without any exceptions (although 2.0 is probably a bad choice for optimization reasons - you want to be as close to actual as possible).
仅当估计行高大于实际行高时,才会出现约束异常.越接近实际,异常发生的可能性就越小.在获得异常之前您的估计可能有多远似乎与几个不同的因素有关:实际行高、行的位置等.
The constraint exception only occurs when the estimated row height is greater than the actual row height. The closer you are to the actual, the less likely the exception will occur. How far off your estimate can be before getting the exception seems to be related to several different factors: actual row height, the position of the row, etc.
这篇关于UITableView 的自动布局错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!