title: iOS8 self-sizing static TableView cells with Interface Builder
body: <p>I am excited by the prospect of being able to build my static TableViews right within Xcode, using Auto Layout to support dynamic type, as mentioned in <a href="http://asciiwwdc.com/2014/sessions/226" rel="noreferrer"><em>WWDC2014 What's New in Table and Collection Views</em></a>.</p>
  
  <p>I'd prefer to use strictly Xcode / Interface Builder and storyboards to handle the Auto Layout. When I do, somehow the TableView cells are not resizing and I'm sure I'm missing something simple. </p>
  
  <p>To reproduce this, using Xcode 7 beta 5, I:</p>
  
  <ul>
  <li>Created a new single view project.</li>
  <li>Set the Storyboard entry point to a new UITableViewController.</li>
  <li>Make it a static table view with grouped style.</li>
  <li>Added a single label to the first row. Added constraints to the top, bottom, left, and right.</li>
  <li>Set the label font to be "Body".</li>
  <li><p>Added to ViewDidLoad:</p>
  
  <p>self.tableView.rowHeight = UITableViewAutomaticDimension;
  self.tableView.estimatedRowHeight = 44.0;</p></li>
  <li><p>Ran it and adjusted Dynamic Type in Settings. While the font changes, the TableView height remains stuck at the apparent default of 44 and truncates the label.</p></li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/MY6jr.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MY6jr.png" alt="Truncated label in Simulator"></a></p>
  
  <p>Here is a <a href="https://github.com/johnstewart/iOS8TableViewAutoLayoutTest" rel="noreferrer">GitHub repository</a> which is the result of the above.</p>
  
  <p>Why isn't Auto Layout causing the TableView to expand to fill the necessary space to fit the new larger label text?</p>
  
  <p>I have found great posts on the subject such as the following, with a bent on using code to set up constraints <a href="https://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights">here</a>.</p>
  
  <p>I'm not finding any examples of doing this in pure Interface Builder. Surely this is quite possible?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I have updated the GitHub source to include a second table row with an ImageView instead of a UILabel; it shows the same issue:</p>
  
  <p><a href="https://i.stack.imgur.com/FQZPC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/FQZPC.png" alt="Updated screenshot"></a></p>
  
  <p>Additionally, when I set an explicit height constraint on either the label or image view, I generate the following. The problem seems to be this "UIView-Encapsulated-Layout-Height" constraint which I have not set. I'm guessing it's generated because in my static tableview in IB, the Row Height is set (as default) to 44. </p>
  
  <pre><code>Unable to simultaneously satisfy constraints.
  ...
  
  "&lt;NSLayoutConstraint:0x7fa371f39e30 V:[UILabel:0x7fa371f38d30'Label'(20)]&gt;",
  "&lt;NSLayoutConstraint:0x7fa371c39160 UILabel:0x7fa371f38d30'Label'.top == UITableViewCellContentView:0x7fa371e17dc0.topMargin&gt;",
  "&lt;NSLayoutConstraint:0x7fa371c393c0 UITableViewCellContentView:0x7fa371e17dc0.bottomMargin == UILabel:0x7fa371f38d30'Label'.bottom&gt;",
  "&lt;NSLayoutConstraint:0x7fa371f41a40 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fa371e17dc0(43.5)]&gt;"
  </code></pre>
  
  <p>But shouldn't this in ViewDidLoad be overriding this?</p>
  
  <pre><code>self.tableView.rowHeight = UITableViewAutomaticDimension;
  self.tableView.estimatedRowHeight = 44.0;
  </code></pre>
  
  <p>Do self-sizing table view cells simply not work with static table views?</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>I have built the same thing using a dynamic prototype instead of a static table view, and all works fine:</p>
  
  <p><a href="https://i.stack.imgur.com/zqRhE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zqRhE.png" alt="enter image description here"></a></p>
  
  <p>It does indeed seem to be static versus dynamic prototyped tables. Static table view cells do not properly expand.</p>
  
  <p>I've seen no mention of dynamic vs. static in the WWDC videos, so at this point I'm chalking this up to a bug. Will update if I learn anything new.</p>
  
  <p>I have updated the GitHub repository above to show an example of both the static (broken) and dynamic (working) table views.</p>