ios - UITableView and Search Bar with Segue -


i have 2 arrays. 1 vehicles, other 1 filteredvehicles. filteredvehicles generating dynamically search bar , work well. can't make dynamically segue next scene.

override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {         self.performseguewithidentifier("displayviewsegue", sender: tableview)     } 

and

// in storyboard-based application, want little preparation before navigation     override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {         if segue.identifier == "displayviewsegue" {             let nextscene  =  segue.destinationviewcontroller as! displayviewcontroller               if sender as! uitableview == self.searchdisplaycontroller!.searchresultstableview {                 let indexpath = self.searchdisplaycontroller!.searchresultstableview.indexpathforselectedrow()!                 let selectedvehicle = self.filteredvehicles[indexpath.row]                 nextscene.currentvehicle = selectedvehicle             } else {                 let indexpath = self.tableview.indexpathforselectedrow()!                 let selectedvehicle = self.vehicles[indexpath.row]                 nextscene.currentvehicle = selectedvehicle             }           }     } 

these methods relating make segue. when click table list object app broking , getting kind of error:

could not cast value of type 'uitableviewcell' (0x10757f9f0) 'uitableview' (0x10757a810). (lldb)

i believe you've set segue in storyboard table view cell next scene. doing this, segue performed automatically, , not have call self.performseguewithidentifier("displayviewsegue", sender: tableview)

the problem of course sender table view cell , not table view, you'd prefer. have couple of options:

  1. remove contents of didselectrowatindexpath, , inside prepareforsegue, obtain reference table view other way.
  2. update storyboard changing segue originate view controller itself, rather table view cell. enable call performseguewithidentifier inside didselectrowatindexpath method.

Comments