ios - A duplicated segue processing with UIStoryBoardSegue between two UIViewControllers -
this question has answer here:
i have 2 screens. first based on uitableview instance. when tap cell, function tableview(_:didselectrowat:)
triggers:
func tableview(_ tableview: uitableview, didselectrowat indexpath: indexpath) { selectedemg = selectedemergencies[indexpath.row] performsegue(withidentifier: "showmoreinfoaboutemg", sender: self) }
here storyboard:
but in fact, segue "showmoreinfoaboutemg" duplicates , second screen.
i can cut performsegue(withidentifier:sender:)
, transition between screens work correctly. need transfer data uitableviewcell
instance remote uiviewcontroller
's property. otherwise this:
prepare(for:sender:)
starts work earlier tableview(_:didselectrowat:)
, remote view controller gets nil object cell. tips, guys?
the decision found.
the simple , useful uitableview's property indexpathforselectedrow
.
i didn't touch storyboard removed tableview(_:didselectrowat:)
implementation , have added 1 line. it's enough use prepare(for:sender:)
totally. general implementation below:
override func prepare(for segue: uistoryboardsegue, sender: any?) { if segue.identifier == "somecustomidentifier" { guard let remoteviewcontroller = segue.destination as? customviewcontroller else { fatalerror("customviewcontroller instance not found 👎🏻") } selecteditem = items[(self.customtableview.indexpathforselectedrow?.row)!] remoteviewcontroller.selecteditemfromtable = selecteditem } }
maybe simpler:
func tableview(_ tableview: uitableview, didselectrowat indexpath: indexpath) { let selectedemg = selectedemergencies[indexpath.row] if let vc = storyboard?.instantiateviewcontroller(withidentifier: "emgdetailspresenter") as? emgdetailspresenter { vc.selectedemgfromtable = selectedemg navigationcontroller?.pushviewcontroller(vc, animated: true) } }
p.s. don't forget remove segue in storyboard , add storyboard id
emgdetailspresenter
Comments
Post a Comment