Swift: return to table view after selecting a search result

I have successfully completed the search function. I want to be able to search my list, select an item in the list, and then return to the main view of the table while the item remains selected. How to do it?

This is a tabular view without a selection or character entered in the search bar. Elements have no detailed representation. Elements have more information that can be obtained, for example. Url This data should be obtained later when the user clicks the "mail" button in the upper left. This is the tableview populated with a subset of the full list (pulled from a test database)

This is a list of search results. The gray highlight of the cell indicates that the cell is selected. How do I return to the main view of a table while maintaining the selection? I see only the cancel button at the top right, the cross button at the top of the search panel and the search button at the bottom right of the keyboard. No one brings you back to the main view of the table, keeping the choice. This is the page with search results.  How do I return to the tableview?

Based on the suggested answers, I was able to save the row index path using the following function:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath       indexPath: NSIndexPath) {
    let rowToSelect = indexPath
    println(rowToSelect)
    selectedCellTitle = selectedCell?.textLabel?.text ?? ""
    println("The stored cell is called \(selectedCellTitle)")
}

However, I was unable to reinstall the row in the main view of the table. My code is below. It seems that the constant "rowToSelect" is not transferred to another function (see the previous line of code). How to fix it?

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> 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
}
+4
source share
2

UITableView Delegate tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath. .
indexPath, selectRowAtIndexPath to (re) .

, tableView

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    //get back to your filled UITableView
    //Save "indexPath" to a variable
}

, UITableView

self.tlbView.selectRowAtIndexPath("above declared variable", animated: true, scrollPosition: .Top)
0

TableViewController, self.tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: .Top), TableView. , , , .

0

All Articles