title: UITableview with dynamic height cells & filling footer view
body: <p>I am trying to make a UITableview with a footer view that fills the remaining empty space of the UITableview. However, the catch is that the cells have varying heights.</p>
  
  <p>I am aware that, if the cells were all a static height, I could simply count how many cells there are and multiply that by the static height. Unfortunately, that won't work in this case.</p>
  
  <p>Current solution:</p>
  
  <p>Works for static height cells.</p>
  
  <p>Does not work for dynamic height cells.</p>
  
  <pre><code>    private func adjustFooterHeight() {
          if data.count == 0 {
              footerView.frame.size.height = tableView.bounds.height
          }
          else {
              //I use data.count instead of (data.count - 1) as I have the extra hidden cell, as pictured in image 2.
              let bottomFrame = tableView.rectForRow(at: IndexPath(row: data.count, section: 0))
              let height = tableView.bounds.height - (bottomFrame.origin.y + bottomFrame.height - rowHeight)
              footerView.frame.size.height = height &lt; 0 ? 0 : height
              tableView.reloadData()
          }
      }
  </code></pre>
  
  <p>Diagram of Intentions:</p>
  
  <p><a href="https://i.stack.imgur.com/cFX8H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cFX8H.png" alt="enter image description here"></a></p>