title: How to adjust UICollectionView contentSize.height based on number of rows in swift
body: <p>I'd really appreciate if someone can light up some ideas here. I've been trying to fix this for weeks now (not kidding).</p>
  
  <p>I have a "to do list" using a collectionView where I hide the rows that were completed and move them to the end of the list. I then unhide the items if needed with a button. The collectionView looks exactly as a tableView with one item(cell) per row.</p>
  
  <p>When the items are hidden the collectionView has a lot of empty scrolling space at the bottom instead of automatically deleting the space used by the hidden rows since they technically are still there.</p>
  
  <p>I'm trying to cut that empty space so the collectionView height would be equal to the amount of cells/rows left visible.</p>
  
  <pre><code>override func viewDidAppear(animated: Bool) {
  
  if isCellHidden { //checking if cells are hidden 
  var heightOfSection0 = 95 + (42 * self.collectionView.numberOfItemsInSection(0))
  println(self.collectionView.contentSize.heigh) //returns 2350
  self.collectionView.contentSize.height = CGFloat(heightOfSection0)
  println(heightOfSection0) //returns 1019
  println(self.collectionView.contentSize.heigh) //returns 1019.0 which is correct but as soon as I scroll down it resets to it's original size (2350) and let's me scroll through that empty space...
  }}
  </code></pre>
  
  <p>If I try to read the collectionView height immediately after setting this, it displays the correct value but as soon as I try to scroll down it resets back to it's original height. I also tried disabling the auto layout and it doesn't make a difference</p>