title: UITableView Section Header Automatic Height Not Updated Properly
body: <p>I am running into an issue with automatic/dynamic UITableView section header views that contain a UILabel that wraps (<em>numberOfLines = 0</em>).  The height is not being calculated properly, especially once you scroll the table and the views are reused.  Sometimes the UILabel wraps, sometimes it is truncated, sometimes one or more of the labels are not visible, and sometimes there is extra spacing between the labels.  The custom view contains a vertical UIStackView with three UILabels, once of which wraps.</p>
  
  <p>A complete sample app demonstrating the issue can be found at <a href="https://github.com/outerstorm/tableviewHeaderTest" rel="noreferrer">https://github.com/outerstorm/tableviewHeaderTest</a>.</p>
  
  <p>The section header heights are set to automatic in viewDidLoad with the following:</p>
  
  <pre><code>    tableView.sectionHeaderHeight = UITableViewAutomaticDimension
      tableView.estimatedSectionHeaderHeight = 30.0
  </code></pre>
  
  <p>and also have implemented the following heightForHeaderInSection just to try to get it to work:</p>
  
  <pre><code>func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -&gt; CGFloat {
      return UITableViewAutomaticDimension
  }
  </code></pre>
  
  <p>I have also tried calling <em>setNeedsLayout()</em> and <em>layoutIfNeeded()</em> at various points to no avail.  Any suggestions would be greatly appreciated.</p>
  
  <p>Below is a screenshot of the behavior seen in the app.  The first section is cutoff and the second section is too tall:</p>
  
  <p><a href="https://i.stack.imgur.com/DCB7a.png" rel="noreferrer"><img src="https://i.stack.imgur.com/DCB7a.png" alt="enter image description here"></a></p>