<i id='yoceA'><tr id='yoceA'><dt id='yoceA'><q id='yoceA'><span id='yoceA'><b id='yoceA'><form id='yoceA'><ins id='yoceA'></ins><ul id='yoceA'></ul><sub id='yoceA'></sub></form><legend id='yoceA'></legend><bdo id='yoceA'><pre id='yoceA'><center id='yoceA'></center></pre></bdo></b><th id='yoceA'></th></span></q></dt></tr></i><div id='yoceA'><tfoot id='yoceA'></tfoot><dl id='yoceA'><fieldset id='yoceA'></fieldset></dl></div>

        <tfoot id='yoceA'></tfoot>
      1. <legend id='yoceA'><style id='yoceA'><dir id='yoceA'><q id='yoceA'></q></dir></style></legend>
        • <bdo id='yoceA'></bdo><ul id='yoceA'></ul>

        <small id='yoceA'></small><noframes id='yoceA'>

        UITableViewCell 中 UILabel 的不明确布局警告

        Ambiguous layout warnings for UILabels in UITableViewCell(UITableViewCell 中 UILabel 的不明确布局警告)

        1. <small id='Bk7qK'></small><noframes id='Bk7qK'>

          <i id='Bk7qK'><tr id='Bk7qK'><dt id='Bk7qK'><q id='Bk7qK'><span id='Bk7qK'><b id='Bk7qK'><form id='Bk7qK'><ins id='Bk7qK'></ins><ul id='Bk7qK'></ul><sub id='Bk7qK'></sub></form><legend id='Bk7qK'></legend><bdo id='Bk7qK'><pre id='Bk7qK'><center id='Bk7qK'></center></pre></bdo></b><th id='Bk7qK'></th></span></q></dt></tr></i><div id='Bk7qK'><tfoot id='Bk7qK'></tfoot><dl id='Bk7qK'><fieldset id='Bk7qK'></fieldset></dl></div>

            <bdo id='Bk7qK'></bdo><ul id='Bk7qK'></ul>
              <legend id='Bk7qK'><style id='Bk7qK'><dir id='Bk7qK'><q id='Bk7qK'></q></dir></style></legend>
              • <tfoot id='Bk7qK'></tfoot>
                    <tbody id='Bk7qK'></tbody>
                  本文介绍了UITableViewCell 中 UILabel 的不明确布局警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 UITableViewCell 中有两个彼此相邻的 UILabel 视图.左边的有一条线,右边的可以有多条线,并使用剩下的任何水平空间.两个标签与单元格顶部的距离相同.单元格的高度由右标签的高度决定.在某些情况下,我会在右侧 UILabel 上方和下方看到不需要的额外空间,因此它们不是顶部对齐的.进一步研究,我发现 hasAmbiguousLayout 为两个标签返回 YES.

                  I have two UILabel views next to each other in an UITableViewCell. The left one has one line, the right one can have multiple lines and uses whatever horizontal space that is left. Both labels have the same distance from the top of the cell. The height of the cell is dictated by the height of the right label. In some cases, I see unwanted additional space above and under the right UILabel, and therefore they are not top-aligned. Looking into it more, I found that hasAmbiguousLayout returns YES for both labels.

                  当我在调试器中调用 constraintsAffectingLayoutForAxis 时,我得到以下输出:

                  When I call constraintsAffectingLayoutForAxis in the debugger, I get the following output:

                  (lldb) po [0x7b769520 constraintsAffectingLayoutForAxis:0]
                  <__NSArrayM 0x7b6cb340>(
                  <NSAutoresizingMaskLayoutConstraint:0x7b76abf0 h=--& v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x7b768fc0]   (Names: '|':MyTVCell:0x7b769330'MyTVCell' )>,
                  <NSLayoutConstraint:0x7b76b010 H:|-(15)-[UILabel:0x7b769520'Number']   (Names: '|':UITableViewCellContentView:0x7b768fc0 )>,
                  <NSContentSizeLayoutConstraint:0x7b769a90 H:[UILabel:0x7b769520'Number'(131)] Hug:250 CompressionResistance:750>
                  )
                  

                  对于位于第一个 UILabel 右侧的第二个 UILabel,我得到这个:

                  For a second UILabel that is positioned to the right of the first UILabel, I get this:

                  (lldb) po [0x7b769710 constraintsAffectingLayoutForAxis:0]
                  <__NSArrayM 0x7b6cb9e0>(
                  <NSContentSizeLayoutConstraint:0x7b769a90 H:[UILabel:0x7b769520'Number'(131)] Hug:250 CompressionResistance:750>,
                  <NSAutoresizingMaskLayoutConstraint:0x7b76abf0 h=--& v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x7b768fc0]   (Names: '|':MyTVCell:0x7b769330'MyTVCell' )>,
                  <NSLayoutConstraint:0x7b76b010 H:|-(15)-[UILabel:0x7b769520'Number']   (Names: '|':UITableViewCellContentView:0x7b768fc0 )>,
                  <NSLayoutConstraint:0x7b76b230 H:[UILabel:0x7b769520'Number']-(15)-[UILabel:0x7b769710'Q12472']>,
                  <NSLayoutConstraint:0x7b76ab90 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7b768fc0(320)]>,
                  <NSLayoutConstraint:0x7b76b310 UILabel:0x7b769710'Q12472'.trailing == UITableViewCellContentView:0x7b768fc0.trailing - 15>
                  )
                  

                  谁能根据上面的输出解释为什么这些标签的布局不明确?

                  Could anyone explain based on the output above why these labels have an ambiguous layout?

                  更新: NSAutoresizingMaskLayoutConstraint 约束属于单元格的 contentView.两个标签都将 translatesAutoresizingMaskIntoConstraints 设置为 NO.

                  Update: The NSAutoresizingMaskLayoutConstraint constraint belongs to the contentView of the cell. Both labels have set translatesAutoresizingMaskIntoConstraints to NO.

                  更新 2: 以下是我对 contentView 和两个标签的限制:

                  Update 2: Here are the constraints I have for the contentView and the two labels:

                  2015-02-26 07:35:25.559 contentView constraints: (
                      "<NSLayoutConstraint:0x7be541e0 V:|-(8)-[UILabel:0x7be537d0]   (Names: '|':UITableViewCellContentView:0x7be535a0 )>",
                      "<NSLayoutConstraint:0x7be54240 H:|-(15)-[UILabel:0x7be537d0]   (Names: '|':UITableViewCellContentView:0x7be535a0 )>",
                      "<NSLayoutConstraint:0x7be54310 V:|-(8)-[UILabel:0x7be53990]   (Names: '|':UITableViewCellContentView:0x7be535a0 )>",
                      "<NSLayoutConstraint:0x7be54340 H:[UILabel:0x7be537d0]-(15)-[UILabel:0x7be53990]>",
                      "<NSLayoutConstraint:0x7be54370 UILabel:0x7be53990.trailing == UITableViewCellContentView:0x7be535a0.trailing - 15>",
                      "<NSLayoutConstraint:0x7be543c0 UILabel:0x7be53990.bottom == UITableViewCellContentView:0x7be535a0.bottom - 8>",
                      "<NSContentSizeLayoutConstraint:0x7be53cd0 H:[UILabel:0x7be537d0(109)] Hug:250 CompressionResistance:750>",
                      "<NSContentSizeLayoutConstraint:0x7be53d10 V:[UILabel:0x7be537d0(21)] Hug:250 CompressionResistance:750>",
                      "<NSContentSizeLayoutConstraint:0x7be53eb0 H:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>",
                      "<NSContentSizeLayoutConstraint:0x7be53f10 V:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>"
                  )
                  2015-02-26 07:35:25.560 left label constraints: (
                      "<NSContentSizeLayoutConstraint:0x7be53cd0 H:[UILabel:0x7be537d0(109)] Hug:250 CompressionResistance:750>",
                      "<NSContentSizeLayoutConstraint:0x7be53d10 V:[UILabel:0x7be537d0(21)] Hug:250 CompressionResistance:750>"
                  )
                  2015-02-26 07:35:25.561 right label constraints:(
                      "<NSContentSizeLayoutConstraint:0x7be53eb0 H:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>",
                      "<NSContentSizeLayoutConstraint:0x7be53f10 V:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750>"
                  )
                  

                  这是一张图片,显示了我的限制以及出了什么问题:

                  Here is a picture showing the constraints I have and what goes wrong:

                  推荐答案

                  我通过为正确的 UILabel 添加解决了它:

                  I solved it by adding for the right UILabel:

                  [self.bodyLabel setContentHuggingPriority: UILayoutPriorityFittingSizeLevel forAxis: UILayoutConstraintAxisHorizontal];
                  

                  另一件事是我在 updateConstraints 中测试歧义,而我应该在 layoutSubviews

                  The other thing is that I was testing for ambiguity in updateConstraints, while I should have done it at the end of layoutSubviews

                  这篇关于UITableViewCell 中 UILabel 的不明确布局警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员

                • <tfoot id='hoMDe'></tfoot>

                      <i id='hoMDe'><tr id='hoMDe'><dt id='hoMDe'><q id='hoMDe'><span id='hoMDe'><b id='hoMDe'><form id='hoMDe'><ins id='hoMDe'></ins><ul id='hoMDe'></ul><sub id='hoMDe'></sub></form><legend id='hoMDe'></legend><bdo id='hoMDe'><pre id='hoMDe'><center id='hoMDe'></center></pre></bdo></b><th id='hoMDe'></th></span></q></dt></tr></i><div id='hoMDe'><tfoot id='hoMDe'></tfoot><dl id='hoMDe'><fieldset id='hoMDe'></fieldset></dl></div>

                        <tbody id='hoMDe'></tbody>

                      <small id='hoMDe'></small><noframes id='hoMDe'>

                      • <bdo id='hoMDe'></bdo><ul id='hoMDe'></ul>

                        <legend id='hoMDe'><style id='hoMDe'><dir id='hoMDe'><q id='hoMDe'></q></dir></style></legend>