ios - didSelectRowAtIndexPath index path with uisearchcontroller -
i have application when user clicks on cell open viewcontroller , add uisearchcontroller
on tableview.
when searching on tableview result correct , when click on cell after filtering , opens wrong page.
my problem don't how identify indexpath
when uiviewcontroller
active make result open correct page
func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { indexpathrow = indexpath.row performseguewithidentifier("toview2", sender: self) }
edit
i solved problem adding new variable in struct of type integer , modify didselectrowatindexpath function
func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { if resultsearchcontroller.active && resultsearchcontroller.searchbar.text != ""{ indexpathrow = filtereddata[indexpath.row].i } else { indexpathrow = indexpath.row } performseguewithidentifier("toview2", sender: self) }
a better way selected item, call indexpathforselectedrow()
method inside of segue delegate
func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { performseguewithidentifier("toview2", sender: self) } override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { if segue.identifier == "toview2" { let indexpath = self.tableview.indexpathforselectedrow() { print("indexpathrow = \(indexpath.row)") //destination controller code goes here ... } } }
Comments
Post a Comment