title: Swift : Clear UITableView Cells
body: <p>I have an variable to store objects of a custom Class which I've loaded into a UITableView.</p>
  
  <p>I'm giving the user an option to clear everything out. When this runs I'm clearing the array that stores all the players but how do I clear the TableView?</p>
  
  <p>I've tried tableView.reloadData() but it doesn't do anything.</p>
  
  <p>Custom Class &amp; Global Variable:</p>
  
  <pre><code>var players: [AnyObject] = []
  Class Player{
      var playerName: String?
  
      init(name:String){
          playerName = name
      }
  }
  </code></pre>
  
  <p>Custom Cell cellForRowAtIndexPath:</p>
  
  <pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
      let cell: CustomMainCell = tableView.dequeueReusableCellWithIdentifier("CustomMainCell") as CustomMainCell
      // Get Player
          let thisPlayer:Player = players[indexPath.row] as Player
  
          cell.nameLabel?.text = thisPlayer.playerName
      }
  
      return cell
  }
  </code></pre>
  
  <p>Settings Clear Function:</p>
  
  <pre><code>alertController.addAction(UIAlertAction(title: "Clear Players?", style: .Default, handler: { (action: UIAlertAction!) in
              players.removeAll()
              self.tableView.reloadData()
          }))
  </code></pre>