ios - didSelectRowAtIndexPath indexpath after filter UISearchController - Swift -


i’m implementing search bar uisearchcontroller within sectioned table. far good.

the main issue when the filtered results come along, it’s whole new table no sections , fewer rows.

when selecting row, perform segue position in array, detailed view expecting exact row or index main array, can’t filtered array of objects, may [0] [1] [2] in 300 elements.

i guess can compare selected object main array , assuming there’s no duplicates, index there , pass over… these seems pretty inefficient me.

apple similar (i unfortunately don’t know how) when filtering contacts, in contacts app. how pass contact object? that’s pretty goal.

here let snippet of i’m doing:

  func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {          if(self.resultsearchcontroller.active) {             customeratindex = indexpath.row // issue here             performseguewithidentifier("showcustomer", sender: nil)         }         else {             customeratindex = returnpositionforthisindexpath(indexpath, insidethistable: tableview)             performseguewithidentifier("showcustomer", sender: nil)         }     }  override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         if segue.identifier == "showcustomer" {             if let destination = segue.destinationviewcontroller as? customerdetailviewcontroller {                 destination.newcustomer = false                 destination.customer = self.customerlist[customeratindex!]                 destination.customeratindex = self.customeratindex!                 destination.customerlist = self.customerlist             }         }     } 

you can either in way, trick, works. first change didselectrowatindexpath below:

func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {         var object :anyobject?         if(self.resultsearchcontroller.active) {             object = filteredarray[indexpath.row]         }         else {             object = self.customerlist[indexpath.row]         }          performseguewithidentifier("showcustomer", sender: object)     } 

now, in prepareforsegue, object , send detailed view controller

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         if segue.identifier == "showcustomer" {         if let destination = segue.destinationviewcontroller as? customerdetailviewcontroller {             destination.newcustomer = false             destination.customer = sender as! customerobject             destination.customeratindex = self.customerlist.indexofobject(destination.customer)             destination.customerlist = self.customerlist         }     } } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -