title: Expand and collapse cells in tableview
body: <p>I have a tableview. Some cells contain images, other text.</p>
  <p>I want to be able to collapse and expand the cells. In order to be able to do so I did the following:</p>
  <p>I created a variable <code>isExpanded = true</code>
  In cellForRowAt I check if the cell contains text and then...</p>
  <pre class="lang-swift prettyprint-override"><code> if textIsExpanded {
                 
    cell.textLabel?.sizeToFit()
    cell.textLabel?.numberOfLines = 0
   }
  </code></pre>
  <p>so that the cell can be as tall as the text inside of it.</p>
  <p>In the action I toggle <code>textIsExpanded</code> and reload the table:</p>
  <pre class="lang-swift prettyprint-override"><code> textIsExpanded.toggle()
   table.reloadData()
  </code></pre>
  <p>This procedure perfectly works with tableviews only containing text.</p>
  <p>Something that would work was expanding the if statement and in the false branch calling:</p>
  <pre class="lang-swift prettyprint-override"><code> cell.textLabel?.invalidateIntrinsicContentSize()
   cell.textLabel?.layoutIfNeeded()     
  </code></pre>
  <p>BUT this doesn't work when I toggle the variable, this only works on launch.</p>
  <p>How can I collapse and expand back the cells in my tableview?</p>