title: UITableView - Index out of range when segment selected while scrolling
body: <p>I am getting "<code>Index out of range</code>" in <code>cellForRowAt</code> when <code>segmentedControl</code> index is changed while scrolling the <code>tableView</code>.</p>
  
  <pre><code>@IBAction func segmentedControlAction(_ sender: AnyObject!) {
          if(segmentedControl.selectedSegmentIndex == 0) {
              self.data?.removeAll()
              loadA()
          }
          else if(segmentedControl.selectedSegmentIndex == 1){
              self.data?.removeAll()
              loadB()
          }
      }
  
   override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
          let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! CustomCell
  
          cell.data = self.data?[indexPath.row] ---&gt; Error here
          return cell
  }
  </code></pre>
  
  <p>LoadA and LoadB are similar functions</p>
  
  <pre><code>func loadA(){
          API.sharedInstance.loadA(start, callback:  { response in
              if let data = response["data"].arrayValue as [JSON]?{
                  self.data = data
                  DispatchQueue.main.async {
                      self.tableView?.reloadData()
                  }
              }
          })
      }
  </code></pre>