title: iOS 11 reloadSections create duplicate header section
body: <p>I'm working on a company's project and I have this problem when testing my table view on iOS 11 GM. It did work well on iOS 10. It is simple, I have three sections with header. When I tap on section header, my section will collapse/extend. Here's how I do it:</p>
  
  <p>ViewController:</p>
  
  <pre><code>class ViewController: UIViewController {
  
  @IBOutlet weak var tableView: UITableView!
  
  var sectionsOpened: [String: Bool] = [
      "section1": true,
      "section2": true,
      "section3": true
  ]
  
  func isSectionOpened(section: String) -&gt; Bool {
      return sectionsOpened[section]!
  }
  
  @objc func toggleSection1() {
      sectionsOpened["section1"] = !sectionsOpened["section1"]!
      toggle(sectionIndex: 0)
  }
  
  @objc func toggleSection2() {
      sectionsOpened["section2"] = !sectionsOpened["section2"]!
      toggle(sectionIndex: 1)
  }
  
  @objc func toggleSection3() {
      sectionsOpened["section3"] = !sectionsOpened["section3"]!
      toggle(sectionIndex: 2)
  }
  
  func toggle(sectionIndex: Int) {
  
      self.tableView.reloadSections([sectionIndex], with: .automatic)
      self.tableView.scrollToRow(at: IndexPath(row: 0, section: sectionIndex), at: .top, animated: true)
  }
  </code></pre>
  
  <p>Table view dataSource:</p>
  
  <pre><code>extension ViewController: UITableViewDataSource {
  func numberOfSections(in tableView: UITableView) -&gt; Int {
      return 3
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return 1
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "testCell", for: indexPath)
      let label = cell.viewWithTag(1) as! UILabel
      label.text = "TEST \(indexPath.section) - \(indexPath.row)"
      return cell
  }
  
  func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -&gt; UIView? {
      let headerView = UILabel(frame: CGRect(x: 0, y: 0, width: 320, height: 60))
      headerView.backgroundColor = UIColor.green
      headerView.text = "Header \(section)"
      var gesture: UITapGestureRecognizer?
      if section == 0 {
          gesture = UITapGestureRecognizer(target: self, action: #selector(toggleSection1))
      } else if section == 1 {
          gesture = UITapGestureRecognizer(target: self, action: #selector(toggleSection2))
      } else if section == 2 {
          gesture = UITapGestureRecognizer(target: self, action: #selector(toggleSection3))
      }
      headerView.addGestureRecognizer(gesture!)
      headerView.isUserInteractionEnabled = true
      return headerView
  }
  
  func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -&gt; CGFloat {
      return 60
  }
  
  func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -&gt; CGFloat {
      return CGFloat.leastNormalMagnitude
  }
  </code></pre>
  
  <p>Table view delegate:</p>
  
  <pre><code>extension ViewController: UITableViewDelegate {
  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
      if !isSectionOpened(section: "section\(indexPath.section+1)") {
          return 1
      }
      if indexPath.section == 0 {
          return 350
      } else if indexPath.section == 1 {
          return 400
      } else if indexPath.section == 2 {
          return 350
      }
      return 500
  }
  </code></pre>
  
  <p>First notice is that scrollToRow behave weird, it go to top, then scroll down to the position.
  Then, after trying to open/close the 3 headers, scrolling up/down, sometimes I got this duplicate header problem:</p>
  
  <p><a href="https://i.stack.imgur.com/HWdti.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HWdti.png" alt="enter image description here"></a><br>
  <a href="https://i.stack.imgur.com/ivSvd.png" rel="nofollow noreferrer">Duplicate header when reloading sections (photo)</a>
  '</p>
  
  <p>Thank you in advance for your help. I really need to make this to work because iOS 11 will come next Tuesday...</p>