title: Dynamic height for UITableViewCell not working correctly
body: <p>I'm having some height problems with my dynamic <code>UITableViewCell</code> (sew picture below). Some cells have the correct height and some not, and when I drag the tableView some of the cells become correct and some don't. </p>
  
  <p>I'm using this code to get the cell's height to be dynamic and reloading it in <code>viewDidAppear</code> and <code>viewDidLoad</code>. </p>
  
  <pre><code>tableView.rowHeight = UITableViewAutomaticDimension
  tableView.estimatedRowHeight = tableView.rowHeight
  </code></pre>
  
  <p>As mentioned the cells are sometimes correct and sometimes not. Is there another way to do it or am I doing something wrong? I have tried many different solutions, all mentioned <a href="https://stackoverflow.com/questions/30494702/dynamic-height-issue-for-uitableview-cells-swift">here</a> as well as other suggestions both here at StackOverflow and other sites. </p>
  
  <p><a href="https://i.stack.imgur.com/wVJCD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wVJCD.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/nkgdt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nkgdt.png" alt="enter image description here"></a></p>
  
  <p>I appreciate all help!</p>
  
  <p>Edit! </p>
  
  <p>TableView</p>
  
  <pre><code>extension ChatVC: UITableViewDelegate, UITableViewDataSource {
      func numberOfSections(in tableView: UITableView) -&gt; Int {
          return 1
      }
  
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return groupMessages.count
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          guard let cell = tableView.dequeueReusableCell(withIdentifier: "groupFeedCell", for: indexPath) as? GroupFeedCell else { return UITableViewCell() }
  
          let message = groupMessages[indexPath.row]
  
              DataService.instance.getUsername(forUID: message.senderId, handler: { (name) in
                  cell.configureCell(name: name, content: message.content)
              })
  
          cell.layoutSubviews()
          cell.layoutIfNeeded()
  
          return cell
      }
  
      func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
  
          return UITableViewAutomaticDimension
      }
  
      func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -&gt; CGFloat {
          return 66
      }
  }
  </code></pre>
  
  <p>Cell </p>
  
  <pre><code>@IBOutlet weak var nameLbl: UILabel!
  @IBOutlet weak var contentLbl: UILabel!
  
  func configureCell(name: String, content: String) {
      self.nameLbl.text = name //email
      self.contentLbl.text = content
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/rIA9G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rIA9G.png" alt="enter image description here"></a></p>