自动布局误差的UITableView [英] Autolayout Error with UITableView

查看:140
本文介绍了自动布局误差的UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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:


  1. 不要使用UITableViewAutomaticDimension 估算的方法。此常量是页眉和页脚的方法。我想我并没有给予足够的重视,当我阅读文档:)的更新:UITableViewAutomaticDimension现在可以在iOS 8的用于行高度,自我上浆细胞功能的一部分。

  1. 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',原因是:表视图行的高度不得为负......'。估计不到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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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