ios - Swift: return to tableview after selecting a search result -
i have implemented search function. want able search list, select item on list, return main tableview while item remains selected. how do this?
this tableview without selections or character typed searchbar. items not have detail view. items have more information can retrieved, e.g. url. data must retrieved later when user presses "mail" button top left.
this list search results. grey highlight of cell indicates cell selected. how return main tableview, whilst keeping selection? see cancel-button top right, cross-button in searchbar top middle, , "search" button on lower right part of keyboard. none bring main tableview whilst storing selection.
based on suggested answers, able store row's index path, using function below:
override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { let rowtoselect = indexpath println(rowtoselect) selectedcelltitle = selectedcell?.textlabel?.text ?? "" println("the stored cell called \(selectedcelltitle)") }
however, haven't succeeded in reselecting row in main tableview. code below. looks constant "rowtoselect" not carried on function (see 1 before last line of code). how fix this?
override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = self.tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) 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 }
the uitableview delegate has function tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath
. function get’s called when row selected.
if listen function , save selected indexpath, can use selectrowatindexpath
(re)select in main view.
implement function listen selections made in tableview
func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { //get filled uitableview //save "indexpath" variable }
when view controller have uitableview
self.tlbview.selectrowatindexpath(“above declared variable”, animated: true, scrollposition: .top)
Comments
Post a Comment