title: iOS - Expand/Collapse UITableView section with animations
body: <p>I want to expand/collapse my <code>UITableView</code> sections with animations. I used <a href="https://stackoverflow.com/questions/1938921/expand-collapse-section-in-uitableview">this</a> answer and it works now if I call <code>self.tableView.reloadData()</code>. But I want that when I tap on my custom <code>UITableView</code>- header , the cells of the section should slide down/up with a nice animation. I tried to use <code>self.tableView.beginUpdates()</code> and <code>self.tableView.endUpdates()</code>, but I get this error:</p>
  
  <pre><code>Invalid update: invalid number of rows in section 0.  The number of rows contained in an 
  existing section after the update (8) must be equal to the number of rows contained in that 
  section before the update (0), plus or minus the number of rows inserted or deleted from 
  that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out 
  of that section (0 moved in, 0 moved out).
  </code></pre>
  
  <p>Here's some code. The method that is called when I tap on the section:</p>
  
  <pre><code>func expand(sender:UITapGestureRecognizer){
  
      let tag = (sender.view?.tag)!
  
      self.tableView.beginUpdates()
      if ausgeklappt[tag] { ausgeklappt[tag] = false }
      else { ausgeklappt[tag] = true }
  
      self.tableView.endUpdates()
  }
  
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      // Return the number of rows in the section.
      let keyDerSection = sortSpieleDict.keys.array[section]
      let arrayDerSection = sortSpieleDict[keyDerSection]!
      if ausgeklappt[section] == false { return 0 } 
      else { return arrayDerSection.count }
  }
  </code></pre>
  
  <p>Thanks.</p>