title: How to set heightForRowAt based the number of numberOfItemsInSection?
body: <p>I'm using <code>UITableViewController</code> and put <code>UICollectionView</code> in second row in Table View Cell. The problem is how I can get heightForRowAt dynamically. </p>
  
  <p>I have tried using <code>return UITableViewAutomaticDimension</code>. But not working.</p>
  
  <p>Any help is really appreciated.</p>
  
  <p><strong>viewDidLoad</strong></p>
  
  <pre><code>override func viewDidLoad() {
          super.viewDidLoad()
  
          self.tableView.estimatedRowHeight = self.tableView.rowHeight
          self.tableView.rowHeight = UITableViewAutomaticDimension
      }
  </code></pre>
  
  <p><strong>UITableViewController</strong></p>
  
  <p><em>Option 1</em></p>
  
  <pre><code> override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
          return self.tableView.bounds.width + 15
      }
  </code></pre>
  
  <p><em>Option 2</em></p>
  
  <pre><code>override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
          return UITableViewAutomaticDimension
      }
  
  override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -&gt; CGFloat {
          return UITableViewAutomaticDimension
      }
  </code></pre>
  
  <p>Currently, I hard code the number of returns.</p>
  
  <p><strong>UICollectionViewDataSource</strong></p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return 15
      }
  </code></pre>
  
  <p><strong>UICollectionViewDelegate, UICollectionViewDelegateFlowLayout</strong></p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
  
          let layout = collectionViewLayout as! UICollectionViewFlowLayout
          layout.minimumLineSpacing = 2.5
          layout.minimumInteritemSpacing = 2.5
  
          itemWidth = (collectionView.bounds.width - 5.0) / 3.0
          return CGSize(width: itemWidth, height: itemWidth)
      }
  </code></pre>
  
  <p>Here is the image of UI using <code>return self.tableView.bounds.width + 15</code> :</p>
  
  <p><a href="https://i.stack.imgur.com/UEtwT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UEtwT.png" alt="enter image description here"></a></p>
  
  <p>Here is the image of UI using <code>return UITableViewAutomaticDimension</code> :</p>
  
  <p><a href="https://i.stack.imgur.com/FNflS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FNflS.png" alt="enter image description here"></a></p>
  
  <p>Here is the image of Constraints :</p>
  
  <p><a href="https://i.stack.imgur.com/jRfTC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jRfTC.png" alt="enter image description here"></a></p>