title: Updating constraint in UITableViewCell not working properly with UIWebView scrollView when zooming
body: <p>I am trying to update the height of a table view cell to match the height of a <code>UIWebView</code> scroll view after zooming in. The <code>UIWebView</code> is a subview of the table view cell.</p>
  
  <p>on    </p>
  
  <pre><code>func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
      DispatchQueue.main.async {
          print("\nscrollViewDidEndZooming")
          print("webView.scrollView.contentSize.height: \(self.webView.scrollView.contentSize.height)")
          print("webViewHeightConstraint: \(self.webViewHeightConstraint.constant)")
  
          let height = self.webView.scrollView.contentSize.height
          self.webViewHeightConstraint.constant = height
          myDelegate.reloadTableView()
      }
  }
  </code></pre>
  
  <p>In parent controller:</p>
  
  <pre><code>func reloadTableView() {
      tableView.beginUpdates()
      tableView.endUpdates() 
  }
  </code></pre>
  
  <p>There is html content loaded on the webview. The problem is, after <code>didEndZooming</code> is called and the height constraint is updated, it isn't setting properly. The height constraint will grow in size until. It seems to me that setting a height constraint in a tableView cell is somehow creating a feed back loop. </p>
  
  <p>How can I make this work how I expect it to? (it should resize to the zoomed value without having the scrollview grow in size unbounded.)</p>
  
  <p>update:
  in </p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: WebViewCell.description(), for: indexPath) as! WebViewCell
  
      //The cell delegate implements the didFinishLoad() function
      cell.delegate = self
  
      //TODO: I know this is not efficient, will update later.
      if let html = viewModel.emailInfo?.htmlContent {
          cell.loadHTMLString(html)
      }
  
      return cell
  }
  </code></pre>
  
  <p>The cell itself is in a xib file. I put the views inside of a dummy view for now (trying to see if this fixed my issue (it didn't). The web view has constraints on the top, bottom, left, and right edges. The webview also has a height constraint. It is this height constraint, <code>webViewHeightConstraint</code>, that I am trying to use to determine the height of the cell. </p>
  
  <p><a href="https://i.stack.imgur.com/XbT38.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XbT38.png" alt="enter image description here"></a></p>
  
  <p>This is the log output after a few cycles of zooming in and out. This is printed before the new height constraint is set:</p>
  
  <blockquote>
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 962.0
    webViewHeightConstraint: 509.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 962.0
    webViewHeightConstraint: 962.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 1531.0
    webViewHeightConstraint: 962.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 1549.0
    webViewHeightConstraint: 1531.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 2566.0
    webViewHeightConstraint: 1549.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 2566.0
    webViewHeightConstraint: 2566.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 4779.0
    webViewHeightConstraint: 2566.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 4779.0
    webViewHeightConstraint: 4779.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 10989.0
    webViewHeightConstraint: 4779.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 10989.0
    webViewHeightConstraint: 10989.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 25110.0
    webViewHeightConstraint: 10989.0</p>
    
    <p>scrollViewDidEndZooming webView.scrollView.contentSize.height: 25110.0
    webViewHeightConstraint: 25110.0</p>
  </blockquote>