Swift/iOS: Collapsing a section in a UITableView
<p>I have a <code>UITableView</code> with about 5 sections. I am trying to collapse and expand one of those section by the click of a button, but I am seeing an issue where the code I'm using to do so results in the collapsing of other sections as well. Specifically, the first row of all visible sections are collapsed. </p>

<p>Here is what that code looks like:</p>

<pre><code>func didClickSectionCollapseButton() {
    shouldCollapseSection = !shouldCollapseSection
    tableView.beginUpdates()
    tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: .Fade)
    tableView.endUpdates()
}
</code></pre>

<p>And here is the <code>numberOfRowInSection</code> method:</p>

<pre><code>override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
    switch section {
    case 0:
        return 1
    case 1:
        // collapsible section
        return shouldCollapse ? 0 : collapsibleSectionCellCount
    case 2:
        return getCellCount()
    case 3:
        return 1
    case 4:
        return 1
    default:
        return 0
    }
}
</code></pre>

<p>Is there anything I'm missing here? I've gone through various tutorials and questions, but I haven't been able to find a solution yet. </p>