title: Ambiguous layout warnings for UILabels in UITableViewCell
body: <p>I have two <code>UILabel</code> views next to each other in an <code>UITableViewCell</code>. 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 <code>UILabel</code>, and therefore they are not top-aligned. Looking into it more, I found that <code>hasAmbiguousLayout</code> returns <code>YES</code> for both labels.</p>
  
  <p>When I call <code>constraintsAffectingLayoutForAxis</code> in the debugger, I get the following output:</p>
  
  
  
  <pre><code>(lldb) po [0x7b769520 constraintsAffectingLayoutForAxis:0]
  &lt;__NSArrayM 0x7b6cb340&gt;(
  &lt;NSAutoresizingMaskLayoutConstraint:0x7b76abf0 h=--&amp; v=--&amp; 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x7b768fc0]   (Names: '|':MyTVCell:0x7b769330'MyTVCell' )&gt;,
  &lt;NSLayoutConstraint:0x7b76b010 H:|-(15)-[UILabel:0x7b769520'Number']   (Names: '|':UITableViewCellContentView:0x7b768fc0 )&gt;,
  &lt;NSContentSizeLayoutConstraint:0x7b769a90 H:[UILabel:0x7b769520'Number'(131)] Hug:250 CompressionResistance:750&gt;
  )
  </code></pre>
  
  
  
  <p>For a second <code>UILabel</code> that is positioned to the right of the first <code>UILabel</code>, I get this:</p>
  
  
  
  <pre><code>(lldb) po [0x7b769710 constraintsAffectingLayoutForAxis:0]
  &lt;__NSArrayM 0x7b6cb9e0&gt;(
  &lt;NSContentSizeLayoutConstraint:0x7b769a90 H:[UILabel:0x7b769520'Number'(131)] Hug:250 CompressionResistance:750&gt;,
  &lt;NSAutoresizingMaskLayoutConstraint:0x7b76abf0 h=--&amp; v=--&amp; 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x7b768fc0]   (Names: '|':MyTVCell:0x7b769330'MyTVCell' )&gt;,
  &lt;NSLayoutConstraint:0x7b76b010 H:|-(15)-[UILabel:0x7b769520'Number']   (Names: '|':UITableViewCellContentView:0x7b768fc0 )&gt;,
  &lt;NSLayoutConstraint:0x7b76b230 H:[UILabel:0x7b769520'Number']-(15)-[UILabel:0x7b769710'Q12472']&gt;,
  &lt;NSLayoutConstraint:0x7b76ab90 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7b768fc0(320)]&gt;,
  &lt;NSLayoutConstraint:0x7b76b310 UILabel:0x7b769710'Q12472'.trailing == UITableViewCellContentView:0x7b768fc0.trailing - 15&gt;
  )
  </code></pre>
  
  
  
  <p>Could anyone explain based on the output above why these labels have an ambiguous layout?</p>
  
  <p><strong>Update:</strong> The <code>NSAutoresizingMaskLayoutConstraint</code> constraint belongs to the <code>contentView</code> of the cell. Both labels have set <code>translatesAutoresizingMaskIntoConstraints</code> to <code>NO</code>.</p>
  
  <p><strong>Update 2:</strong> Here are the constraints I have for the contentView and the two labels:</p>
  
  
  
  <pre><code>2015-02-26 07:35:25.559 contentView constraints: (
      "&lt;NSLayoutConstraint:0x7be541e0 V:|-(8)-[UILabel:0x7be537d0]   (Names: '|':UITableViewCellContentView:0x7be535a0 )&gt;",
      "&lt;NSLayoutConstraint:0x7be54240 H:|-(15)-[UILabel:0x7be537d0]   (Names: '|':UITableViewCellContentView:0x7be535a0 )&gt;",
      "&lt;NSLayoutConstraint:0x7be54310 V:|-(8)-[UILabel:0x7be53990]   (Names: '|':UITableViewCellContentView:0x7be535a0 )&gt;",
      "&lt;NSLayoutConstraint:0x7be54340 H:[UILabel:0x7be537d0]-(15)-[UILabel:0x7be53990]&gt;",
      "&lt;NSLayoutConstraint:0x7be54370 UILabel:0x7be53990.trailing == UITableViewCellContentView:0x7be535a0.trailing - 15&gt;",
      "&lt;NSLayoutConstraint:0x7be543c0 UILabel:0x7be53990.bottom == UITableViewCellContentView:0x7be535a0.bottom - 8&gt;",
      "&lt;NSContentSizeLayoutConstraint:0x7be53cd0 H:[UILabel:0x7be537d0(109)] Hug:250 CompressionResistance:750&gt;",
      "&lt;NSContentSizeLayoutConstraint:0x7be53d10 V:[UILabel:0x7be537d0(21)] Hug:250 CompressionResistance:750&gt;",
      "&lt;NSContentSizeLayoutConstraint:0x7be53eb0 H:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750&gt;",
      "&lt;NSContentSizeLayoutConstraint:0x7be53f10 V:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750&gt;"
  )
  2015-02-26 07:35:25.560 left label constraints: (
      "&lt;NSContentSizeLayoutConstraint:0x7be53cd0 H:[UILabel:0x7be537d0(109)] Hug:250 CompressionResistance:750&gt;",
      "&lt;NSContentSizeLayoutConstraint:0x7be53d10 V:[UILabel:0x7be537d0(21)] Hug:250 CompressionResistance:750&gt;"
  )
  2015-02-26 07:35:25.561 right label constraints:(
      "&lt;NSContentSizeLayoutConstraint:0x7be53eb0 H:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750&gt;",
      "&lt;NSContentSizeLayoutConstraint:0x7be53f10 V:[UILabel:0x7be53990(20)] Hug:250 CompressionResistance:750&gt;"
  )
  </code></pre>
  
  
  
  <p>Here is a picture showing the constraints I have and what goes wrong:</p>
  
  <p><img src="https://i.stack.imgur.com/EhFgc.png" alt="enter image description here"></p>