title: Dynamically-sized UITableView in UIScrollView with Auto-Layout
body: <p>There are a million questions about auto-layout and UIScrollViews, but I think this is something different.</p>
  
  <p>I have a construct that looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/U9aKr.png" alt="Resizing Example"></p>
  
  <p>The white background is a UIView which acts as a container within a UIScrollView (the typical setup for get a scroll view to build its own content size so it scrolls properly based on the container view).</p>
  
  <p>TableView 1 and TableView 2 need to have their heights be dynamic.  I don't want them scrolling, so I need to set their frame height equal to their content height.</p>
  
  <p>I have IBOutlets for the height constraint for each of these, and can adjust them with no problem.</p>
  
  <p>The issue arises when I try to adjust the height of the container view.  Ultimately, I would like to not have to mess with it and let that view resize automatically based on its content, but that does not seem to be working (if I leave off the height of the container view, I get warnings/errors in IB about the constraints).</p>
  
  <p>If I create an outlet to the container view's height constraint and set it, I get an assert fail:</p>
  
  <pre><code>*** Assertion failure in -[UIView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2935.137/UIView.m:8803
  </code></pre>
  
  <p>I am doing the constraint adjusting in viewDidLayoutSubviews like this:</p>
  
  <pre><code>- (void)viewDidLayoutSubviews {
      self.orderItemTableViewHeightConstraint.constant = self.orderItemTableView.contentSize.height - [self tableView:self.orderItemTableView heightForHeaderInSection:0];
      self.shippingOptionTableViewHeightConstraint.constant = self.shippingMethodTableView.contentSize.height;
      self.scrollViewContainerViewHeightConstraint.constant = self.cardInfoLabel.$bottom + 60;
  }
  </code></pre>
  
  <p>I believe the problem is setting the container view's height constraint is causing some recursion or something...</p>
  
  <p>The questions:</p>
  
  <ol>
  <li>IS there a way to let the container view's height be fluid based on its content in this situation?</li>
  <li>If not, how do I handle this programmatically?  Am I altering the constraints in the wrong place or something?</li>
  </ol>
  
  <p>Thanks for any input!</p>