title: Conditionally change height of cells in UITableView
body: <p>I am making a form in a tableview.</p>
  
  <p>Let's say I have 4 different types of cells, each being a question with different kind of answers</p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      if sortedFixedContentType.count != 0 {
          let item = sortedFixedContentType[indexPath.row]
  
          switch item.typeId {
          case "1":
              let cell = tableView.dequeueReusableCell(withIdentifier: "FirstCell", for: indexPath) as! FirstCell
              return cell;
  
          case "2":
              let cell = tableView.dequeueReusableCell(withIdentifier: "SecondCell", for: indexPath) as! SecondCell
              cell.customDelegate = self
              return cell;
          case "3":
              let cell = tableView.dequeueReusableCell(withIdentifier: "ThirdCell", for: indexPath) as! ThirdCell
              cell.commentsTextView.delegate = self
              return cell;
  
          case "4":
              let cell = tableView.dequeueReusableCell(withIdentifier: "FourthCell", for: indexPath) as! FourthCell
              return cell;
  
  }
  </code></pre>
  
  <p>When the tableView is loaded I want to show only first cell, and depending on the answer different cells will be shown.</p>
  
  <p>For example:</p>
  
  <p>FirstCell can be answered with <strong>A</strong>, <strong>B</strong>, or <strong>C</strong>, </p>
  
  <p>If I answer <strong>A</strong> <code>SecondCell</code> will be shown with answers <strong>X</strong> and <strong>Y</strong>. </p>
  
  <p>If <strong>X</strong> is the answers <code>ThirdCell</code> will be shown (which has no options but a TextField), and when completed <code>FourthCell</code> will be shown</p>
  
  <p><strong>But</strong> if in <code>FirstCell</code> the answer is <strong>B</strong> or <strong>C</strong> only <code>FourthCell</code> will be directly shown.</p>
  
  <p>At the moment I was doing it by changing the height of the rows in <code>heightForRowAt</code>, although I think there must be an easier way. 
  However I'm finding a problem:</p>
  
  <p>If I get to the textField in <code>ThirdCell</code> and then I change my first answer, <code>SecondCell</code> is hidden but <code>ThirdCell</code> is not, as the condition to it was the second answer and it's already made, so I thought on setting the height of each row as condition to, but I don't know how to do it.</p>
  
  <p>So I have two main questions:</p>
  
  <ul>
  <li><p>Is it possible to access to the <code>heightForRowAt</code> to set it as a condition?</p></li>
  <li><p>Should I make it this way? or maybe there's a better way to get what I need? I read about adding and deleting rows dynamically to tableviews but with the same cell type, this is why I decided to hide them by their height instead.</p></li>
  </ul>
  
  <p>Thanks in advance!</p>