title: How to select a UITableview Cell automatically?
body: <p>I'm working on a Quiz App. I am getting questions from API. I'm using tableview for the Options. </p>
  
  <p>Now when the user selects the answer for the 1st question &amp; presses Next comes to the previous question. Then the selected answer has to remain selected.</p>
  
  <p>I researched a lot and found this:</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/24787098/programmatically-emulate-the-selection-in-uitableviewcontroller-in-swift">Programmatically emulate the selection in UITableViewController in Swift</a></p>
  </blockquote>
  
  <p>But I can't automatically select the user selected answer in my table view. </p>
  
  <p>This is my <a href="https://i.imgur.com/kMZuPKu.png" rel="nofollow noreferrer">Present UI</a></p>
  
  <p><strong>VC</strong></p>
  
  <pre><code>func getOptions(){
      OptionArray.removeAll(keepCapacity: false)
      Alamofire.request(.GET, "http://www.wins.com/index.php/capp/get_chapter_answers/\(EID)/\(QuestionID[Qindex])")
          .responseJSON { (_, _, data, _) in
              println(data)
              let json = JSON(data!)
              let catCount = json.count
              for index in 0...catCount-1 {
                  let disp = json[index]["DISPLAY_STATUS"].string
                  if disp == "Y"{
                  let op = json[index]["ANSWER"].string
                  self.OptionArray.append(op!)
                  let ans = json[index]["RIGHT_ANSWER"].string
                  self.AnswerArray.append(ans!)
                  }
              }
              self.OptionTable.reloadData()
              println(self.OptionArray.count)
      }
  }
  
  @IBAction func Previous(sender: AnyObject) {
      Qindex--
      ShowQuestion()
  }
  
  
  @IBAction func Next(sender: AnyObject) {
      Qindex++
      ShowQuestion()
     }
  
  
  func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      return 1
  }
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
      return self.OptionArray.count
  }
  
  
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
      let cell = self.OptionTable.dequeueReusableCellWithIdentifier("Option") as! OptionCell
  
      cell.Optionlabel?.text = self.OptionArray[indexPath.row]
      cell.layer.masksToBounds = true;
      cell.layer.cornerRadius = 6;
      cell.layer.borderWidth = 2.0
      cell.layer.borderColor = colorsArray[1].CGColor
      return cell
  
  }
  
  func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  
      let indexPath = tableView.indexPathForSelectedRow();
  
      let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! OptionCell;
  
      if currentCell.selected == true{
          currentCell.layer.borderWidth = 4.0
          currentCell.layer.borderColor = colorsArray[6].CGColor
          println(currentCell.Optionlabel?.text)
      }
  }
  
  func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
  
  
      let currentCell = tableView.cellForRowAtIndexPath(indexPath) as! OptionCell;
  
      if currentCell.selected == false{
          currentCell.layer.borderWidth = 2.0
          currentCell.layer.borderColor = colorsArray[1].CGColor
  
      }
  }
  
  func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -&gt; CGFloat {
      return 70
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <ol>
  <li><p>I have over 20 Questions. So i have to save the Selected answer for Each Questions separately.</p></li>
  <li><p>I can't select the answer using the indexpath position because the options will change it positions randomly when it is accessed for the second time.</p></li>
  </ol>