title: When I use Auto Layout to choose each cell's height (so they're dynamic) it mostly works, but some cells are a little short. Why is this?
body: <p><strong>Example project:</strong> <a href="http://cl.ly/2j0A1J203f3h" rel="nofollow noreferrer">http://cl.ly/2j0A1J203f3h</a></p>
  
  <p>I'm trying to use Auto Layout to dynamically determine each cell's height so some cell's can hold more content than others. To do this I'm using <a href="https://stackoverflow.com/a/18746930/998117">this Stackoverflow answer</a> and the <a href="https://github.com/caoimghgin/TableViewCellWithAutoLayout" rel="nofollow noreferrer">accompanying GitHub example</a>.</p>
  
  <p>I have a <code>UITableViewCell</code> subclass called <code>CSPostCell</code> that I created in the Storyboard and put a <code>UILabel</code> in with a maximum of 5 lines of text in the label.</p>
  
  <p>Just for example purposes, I'm only having two cells in the table and as such two different pieces of text for the labels (one's longer) which is set up in <code>cellForRowAtIndexPath:</code>:</p>
  
  <pre><code>- (CSPostCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      CSPostCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SelfPostCell" forIndexPath:indexPath];
      cell.postTitle.text = indexPath.row == 0 ? @"Short title" : @"Long long long title. Holy crap this is one long title. When does it end? Oh right now.";
      [cell setNeedsUpdateConstraints];
  
      return cell;
  }
  </code></pre>
  
  <p>I then return the height of each cell as such:</p>
  
  <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
      CSPostCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SelfPostCell"];
  
      cell.postTitle.text = indexPath.row == 0 ? @"Short title" : @"Long long long title. Holy crap this is one long title. When does it end? Oh right now.";
      cell.postTitle.preferredMaxLayoutWidth = tableView.bounds.size.width - 40;
  
      [cell setNeedsUpdateConstraints];
      [cell updateConstraintsIfNeeded];
      [cell.contentView setNeedsLayout];
      [cell.contentView layoutIfNeeded];
  
      CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
  
      return height;
  }
  </code></pre>
  
  <p>Which is more or less an exact copy from the <a href="https://github.com/caoimghgin/TableViewCellWithAutoLayout/blob/master/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m#L120" rel="nofollow noreferrer">GitHub repo example</a>.</p>
  
  <p>However, when I run the app in the simulator, it doesn't quite work as it should. The heights are dynamic and adjust for longer pieces of text, but not enough that the text doesn't get cut off. See the image below:</p>
  
  <p><img src="https://i.stack.imgur.com/DdddI.png" alt="enter image description here"></p>
  
  <p>In that above case the second cell's label should show another line to finish off the text, but it gets cut off. </p>
  
  <p>Why is it not showing all the text?</p>