title: how to add a second section in a tableView depending on a bool value Swift
body: <p>I'm trying to add a second section to my tableView. I want to be able to transfer the row from section 1 when the checkbox inside the cell is pressed and make it appear in the second section and vice versa.</p>
  
  <p>I searched on the forum and found only how to sort sections by date.</p>
  
  <p>Please check my commented lines to understand where I have questions.</p>
  
  <p>here is what I have</p>
  
  <pre class="lang-cs prettyprint-override"><code>var cellItemData = [String]() //this is my main table data
  var checkedCells = Array(count: cellItemData.count, repeatedValue:false) // this is where I assign false to all my unchecked rows in section 0
  var secondSectionData = [String]() //this is where I store the cells for the second section
  
  
  
  func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
     return 2
   }
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt;     Int{
  
         if section == 0 {
       return cellItemData.count
                         }
         if section == 1 {
       secondSectionData.count
                         } 
         return 0
     }
  
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; TableViewCell {
  
          var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TableViewCell       
  
             if checkedCells[indexPath.row] == false{
  
          cell.checkBoxImage.setImage(UIImage(named:"unchecked"),forState:UIControlState.Normal)
  
          } else if checkedCells[indexPath.row] == true {
  
          cell.checkBoxImage.setImage(UIImage(named:"checked"),forState:UIControlState.Normal)
  
          }
  
         cell.textLabel?.text = cellItemData[indexPath.row]
         // what about the cells in the other section?
  
         cell.checkBoxImage.tag = indexPath.row
  
         cell.checkBoxImage?.addTarget(self, action: "buttonTouched:", forControlEvents: UIControlEvents.TouchUpInside)
  
      return cell
  }
  
   func buttonTouched(sender: UIButton){
  
       for item in cellItemData {
          var i = 0
          if checkedCells[i] == true
          {
              secondSectionData.append(item)
  
              //tableView!.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection:1)], withRowAnimation: .Automatic)
              //self.tableView.reloadData()
              //not sure if this is the right way
              i++
  
          }
      }
  
     let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: sender.tag, inSection: 0)) as TableViewCell
      cellItemData.removeAtIndex(sender.tag)
      checkedCells.removeAtIndex(sender.tag)
      tableView!.deleteRowsAtIndexPaths([NSIndexPath(forRow: sender.tag, inSection:0)], withRowAnimation: .Fade)
      self.tableView.reloadData()
  
    }
  </code></pre>