title: iOS: Dynamically set UITableView height in Swift
body: <p>Our UITableView exists on a ViewController (and not a TableViewController).  We populate it at run time with two rows.  When we set a height constraint the table appears fine.  When we <em>don't</em> set the height constraint the table completely does not appear.  How can you set the UITableView to dynamically set its height?   </p>
  
  <p>I've seen threads about dynamically setting the row height (which does work well) but not about the actual table height.  There are a few threads on this specific point but none seem to work for me.  </p>
  
  <hr>
  
  <p><strong>Update on solution</strong>: As Robotic Cat suggested we set up a height constraint on the <code>UITableView</code> in the Storyboard (we had that already) and then did Ctrl drag to create an <code>IBOutlet</code> in our controller.  From there we executed the following code in <code>viewWillAppear</code> per Vignesh's answer:</p>
  
  <pre><code>tableViewHeightConstraint.constant = tableView.contentSize.height
  </code></pre>
  
  <p>Note before executing the above code we are calling <code>reloadData()</code> in the same method to populate our table.</p>