title: Jerky Scrolling After Updating UITableViewCell in place with UITableViewAutomaticDimension
body: <p>I am building an app that has a feed view for user-submitted posts. This view has a <code>UITableView</code> with a custom <code>UITableViewCell</code> implementation. Inside this cell, I have another <code>UITableView</code> for displaying comments. The gist is something like this:</p>
  
  <pre><code>Feed TableView
    PostCell
      Comments (TableView)
        CommentCell
    PostCell
      Comments (TableView)
        CommentCell
        CommentCell
        CommentCell
        CommentCell
        CommentCell
  </code></pre>
  
  <p>The initial feed will download with 3 comments for previewing, but if there are more comments, or if the user adds or deletes a comment, I want to update the <code>PostCell</code> in place inside of the feed table view by adding or removing <code>CommentCells</code> to the comments table inside of the <code>PostCell</code>. I am currently using the following helper to accomplish that:</p>
  
  <pre><code>// (PostCell.swift) Handle showing/hiding comments
  func animateAddOrDeleteComments(startRow: Int, endRow: Int, operation: CellOperation) {
    let table = self.superview?.superview as UITableView
  
    // "table" is outer feed table
    // self is the PostCell that is updating it's comments
    // self.comments is UITableView for displaying comments inside of the PostCell
    table.beginUpdates()
    self.comments.beginUpdates()
  
    // This function handles inserting/removing/reloading a range of comments
    // so we build out an array of index paths for each row that needs updating
    var indexPaths = [NSIndexPath]()
    for var index = startRow; index &lt;= endRow; index++ {
      indexPaths.append(NSIndexPath(forRow: index, inSection: 0))
    }
  
    switch operation {
    case .INSERT:
      self.comments.insertRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.None)
    case .DELETE:
      self.comments.deleteRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.None)
    case .RELOAD:
      self.comments.reloadRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.None)
    }
  
    self.comments.endUpdates()
    table.endUpdates()
  
    // trigger a call to updateConstraints so that we can update the height constraint 
    // of the comments table to fit all of the comments
    self.setNeedsUpdateConstraints()
  }
  
  override func updateConstraints() {
    super.updateConstraints()
    self.commentsHeight.constant = self.comments.sizeThatFits(UILayoutFittingCompressedSize).height
  }
  </code></pre>
  
  <p>This accomplishes the update just fine. The post is updated in place with comments added or removed inside of the <code>PostCell</code> as expected. I am using auto sizing <code>PostCells</code> in the feed table. The comments table of the <code>PostCell</code> expands to show all of the comments, but the animation is a bit jerky and the table sort of scrolls up and down a dozen pixels or so while the cell update animation takes place.</p>
  
  <p>The jumping during resizing is a bit annoying, but my main issue comes afterwards. Now if I scroll down in the feed, the scrolling is smooth as before, but if I scroll up above the cell I just resized after adding comments, the feed will jump backwards a few times before it reaches the top of the feed. I setup <code>iOS8</code> auto sizing cells for the Feed like this:</p>
  
  <pre><code>// (FeedController.swift)
  // tableView is the feed table containing PostCells
  self.tableView.rowHeight = UITableViewAutomaticDimension
  self.tableView.estimatedRowHeight = 560
  </code></pre>
  
  <p>If I remove the <code>estimatedRowHeight</code>, the table just scrolls to the top anytime a cell height changes. I'm feeling pretty stuck on this now and as a new iOS developer, could use any tips you might have.</p>