title: TableView AllowsMultipleSelection - Still allowing multiple selections
body: <p>I posted earlier - on how to stop multiple cells from being able to be selected in my table view - the answer was to use <code>tableView.AllowsMultipleSelections=false</code></p>
  
  <p>I have been trying and failing miserably since, essentially it doesn't seem to be obeying that rule.</p>
  
  <p>My desired output should be one cell is selected and has a green tick next to it (this works) if a new cell is selected, the old tick is removed and moved to the new current cell.</p>
  
  <p>I have tried many approaches and the latest is to create my own index path from the last index selected - then set the accessory view to nil and change selected to false. This also does not work. Please could someone help me with what I might be doing wrong.</p>
  
  <p>Thanks </p>
  
  <pre><code>import UIKit
  
  class QuizViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
  
      var countries = ["Germany", "France", "England", "Poland", "Spain"];
  
      var selected = -1;
  
      @IBOutlet var tableView: UITableView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          self.tableView.allowsMultipleSelection = false;
  
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
  
  
      func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
          return 1;
      }
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return self.countries.count;
      }
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          println("indexpath \(indexPath.row)");
          let cell = self.tableView.dequeueReusableCellWithIdentifier("CountryCell", forIndexPath: indexPath) as UITableViewCell
  
          cell.textLabel?.text = self.countries[indexPath.row];
          cell.textLabel?.textAlignment = NSTextAlignment.Center;
  
  
          let countryImage = String(self.countries[indexPath.row]) + ".png";
          cell.imageView?.image = UIImage(named: countryImage);
  
          let image: UIImageView = UIImageView();
          cell.accessoryView = image;
          return cell;
      }
  
  
      func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
  
          var cell = self.tableView.dequeueReusableCellWithIdentifier("CountryCell", forIndexPath: indexPath) as UITableViewCell
  
          cell.textLabel?.text = self.countries[indexPath.row];
          cell.textLabel?.textAlignment = NSTextAlignment.Center;
  
  
          let countryImage = String(self.countries[indexPath.row]) + ".png";
          cell.imageView?.image = UIImage(named: countryImage);
  
  
          let imageName = "tick.png";
          let image: UIImageView = UIImageView(image: UIImage(named: imageName));
          cell.accessoryView = image;
  
          if(selected != -1){
              //lets remove the tick from the previously selected cell and set selected to false
  
              var cell = self.tableView.dequeueReusableCellWithIdentifier("CountryCell", forIndexPath: NSIndexPath(forRow: selected, inSection: 0)) as UITableViewCell
  
              cell.accessoryView = nil;
              cell.selected = false;
          }
  
          selected = indexPath.row;
      }
  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/PQChp.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/r8dJ0.png" alt="enter image description here"></p>
  
  <p><strong>Attempt at proposed solution</strong></p>
  
  <pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
      let cell = self.tableView.dequeueReusableCellWithIdentifier("CountryCell", forIndexPath: indexPath) as UITableViewCell
  
      cell.textLabel?.text = self.countries[indexPath.row];
      cell.textLabel?.textAlignment = NSTextAlignment.Center;
  
      let countryImage = String(self.countries[indexPath.row]) + ".png";
      cell.imageView?.image = UIImage(named: countryImage);
  
  
      if(cell.selected){
          println("cell was set to selected at \(indexPath.row)");
          let imageName = "tick.png";
          let image: UIImageView = UIImageView(image: UIImage(named: imageName));
          cell.accessoryView = image;
      }else{
          println("cell was NOT set to selected at \(indexPath.row)");
          let image: UIImageView = UIImageView();
          cell.accessoryView = image;
      }
  
      return cell;
  }
  
  
  func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
  
  
      var cell = self.tableView.dequeueReusableCellWithIdentifier("CountryCell", forIndexPath: indexPath) as UITableViewCell
      cell.selected = true;
  
      if(selected != -1){
          var previous = self.tableView.dequeueReusableCellWithIdentifier("CountryCell", forIndexPath: NSIndexPath(forRow: selected, inSection: 0)) as UITableViewCell
          previous.selected = false;
      }
      selected = indexPath.row;
      tableView.reloadData();
  }
  </code></pre>