title: Swift: return to tableview after selecting a search result
body: <p>I have successfully implemented a search function. I want to be able to search my list, select an item on the list, then return to the main tableview while the item <em>remains</em> selected. How do I do this?</p>
  
  <p><strong>This is the tableview without any selections or character typed into the searchbar. Items do not have a detail view. Items do have more information that can be retrieved, e.g. url. This data must be retrieved later when a user presses the "mail" button top left.</strong>
  <img src="https://i.stack.imgur.com/ZaJyn.png" alt="This is the tableview populated with a subset of the full list (pulled from a test database)"></p>
  
  <p><strong>This is the list with search results. The grey highlight of the cell indicates that the cell is selected. How do I now return to the main tableview, whilst keeping the selection? I only see the cancel-button top right, the cross-button in the searchbar top middle, and the "search" button on the lower right part of the keyboard. None bring you back to the main tableview whilst storing the selection.</strong>
  <img src="https://i.stack.imgur.com/acrn9.png" alt="This is the page with search results. How do I return to the tableview?"></p>
  
  <p>Based on the suggested answers, I was able to store the row's index path, using the function below:</p>
  
  <pre><code>override func tableView(tableView: UITableView, didSelectRowAtIndexPath       indexPath: NSIndexPath) {
      let rowToSelect = indexPath
      println(rowToSelect)
      selectedCellTitle = selectedCell?.textLabel?.text ?? ""
      println("The stored cell is called \(selectedCellTitle)")
  }
  </code></pre>
  
  <p>However, I haven't succeeded in reselecting the row in the main tableview. My code is below. It looks like the constant "rowToSelect" is not carried over to another function (see the one before last line of code). How do I fix this? </p>
  
  <pre><code>override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
          if tableView == self.searchDisplayController!.searchResultsTableView {
              cell.textLabel?.text = filteredPublications[indexPath.row].valueForKey("fullTitle") as? String
              cell.detailTextLabel?.text = filteredPublications[indexPath.row].valueForKey("journal") as? String
          } else {
              cell.textLabel?.text = publications[indexPath.row].valueForKey("fullTitle") as? String
              cell.detailTextLabel?.text = publications[indexPath.row].valueForKey("journal") as? String
              self.tableView.selectRowAtIndexPath(rowToSelect, animated: true, scrollPosition: .Top)
          }
  return cell
  }
  </code></pre>