title: Dynamic DataSource swap for UITableView in Swift
body: <p>I am new to iOS/Swift development, and having a problem with making a dynamic swap of DataSource work for a UITableView - note I am not swapping the Delegate, just the DataSource.</p>
  
  <p>I have read other similar questions/responses on Stack Overflow, and not found one that's relevant to my situation. Typically they're about setting the DataSource on "viewDidLoad" (e.g. <a href="https://stackoverflow.com/questions/25075646/how-can-i-programmatically-set-datasource-of-uitableview">this one</a>, and <a href="https://stackoverflow.com/questions/32806402/dynamic-datasource-delegates-for-uitableview-in-swift?noredirect=1&amp;lq=1">this one</a>), whereas my situation is about swapping the DataSource when the user presses a button. The problems in the referenced questions don't exist in my code. </p>
  
  <p>Here's outline of my code. I have the buttonPress method connected to the TouchUpInside event in the storyboard:</p>
  
  <pre><code>class ViewController: UIViewController, UITableViewDelegate {
  
      @IBOutlet weak var tableView: UITableView!
  
      ...    
  
      @IBAction func buttonPress(sender: UIButton) {
  
          ...
  
          self.tableView.dataSource = DummyDataSource()
          self.tableView.delegate = self
          self.tableView.reloadData()
  
      }
  
      ...
  
  }
  </code></pre>
  
  <p>...and here's my datasource class:</p>
  
  <pre><code>import UIKit
  
  class DummyDataSource: NSObject, UITableViewDataSource {
  
      let names = ["A", "B", "C"]
  
      func tableView(tableView: UITableView,
                       numberOfRowsInSection section: Int) -&gt; Int {
          return names.count
      }
  
      func tableView(tableView: UITableView,
                       cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
          var cell = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier) as UITableViewCell?
  
          if ( cell == nil ) {
              cell = UITableViewCell( style: UITableViewCellStyle.Default,
                                  reuseIdentifier: simpleTableIdentifier)
          }
  
          cell!.textLabel?.text = names[indexPath.row]
          return cell!
  
      }
  
  }
  </code></pre>
  
  <p>When I press the button, I can see that the pressButton method is being called correctly, but the data doesn't show up in the tableView (no errors - just no data). Any ideas please? Thank you.</p>