title: Moving sections between each other with long press in TableView
body: <p>I have a <code>tableview</code> which includes expandable and collapsible cells with using section. You can see below my example code part.</p>
  
  <pre><code>class MainViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  
  @IBOutlet weak var mainTableView: UITableView!
  
  var allSections = [AllSections]()
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      // Do any additional setup after loading the view.
  
      let section1 = AllSections(title: "Header 1", rows: ["row 1", "row 2"], isSelected: false)
      let section2 = AllSections(title: "Header 2", rows: ["row 1", "row 2", "row 3"], isSelected: false)
      let section3 = AllSections(title: "Header 3", rows: ["row 1", "row 2", "row 3", "row 4"], isSelected: false)
  
      allSections.append(section1)
      allSections.append(section2)
      allSections.append(section3)
  
      let mainTableViewCellNib: UINib = UINib.init(nibName: "MainTableViewCell", bundle: Bundle.main)
      mainTableView.register(mainTableViewCellNib, forCellReuseIdentifier: "MainTableViewCell")
  
  }
  
  func numberOfSections(in tableView: UITableView) -&gt; Int {
      return allSections.count
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
        let sectionRow = self.allSections[section]
        return sectionRow.rows.count
    }
  
  func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -&gt; UIView? {
  
      let sectionView: SectionView = Bundle.main.loadNibNamed("SectionView", owner: self, options: nil)?[0] as! SectionView
  
         let sectionRow = self.allSections[section]
  
        sectionView.sectionTitleLabel.text = sectionRow.title
        sectionView.sectionButtonOutlet.addTarget(self, action: #selector(openRows), for: .touchUpInside)
        sectionView.sectionButtonOutlet.tag = section
  
        return sectionView
    }
  
  func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -&gt; CGFloat {
      return 61
    }
  
  func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -&gt; CGFloat {
         return 5
    }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
        let identifier: String = "MainTableViewCell"
        let cell: MainTableViewCell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as! MainTableViewCell
  
        let sectionRows = self.allSections[indexPath.section]
        cell.testLabel.text = sectionRows.rows[indexPath.row]
  
        return cell
    }
  
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
   {
  
   }
  
  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
  
      let sectionRows = self.allSections[indexPath.section]
  
      if sectionRows.isSelected {
          return 41
      }else 
       {
          return 0
      }        
  }
  
  @objc func openRows(sender: UIButton!) {
  
      let section = sender.tag
  
      let sectionRow = self.allSections[section]
      sectionRow.isSelected = !sectionRow.isSelected
      mainTableView.reloadSections([section], with: UITableViewRowAnimation.automatic)
  
    }
  
  }
  </code></pre>
  
  <p>Output:</p>
  
  <p><a href="https://i.stack.imgur.com/DwHFZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DwHFZ.png" alt="enter image description here"></a></p>
  
  <p>When I would long press section, Is it possible to change section with all rows order like changing cells order?</p>
  
  <p>I searched lots of hours about it, but I couldn't find any information. Can you help me with it, please? Thanks for your advices.</p>