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:

storyboard

but in fact, segue "showmoreinfoaboutemg" duplicates , second screen.

enter image description here

i can cut performsegue(withidentifier:sender:) , transition between screens work correctly. need transfer data uitableviewcell instance remote uiviewcontroller's property. otherwise this:

enter image description here

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

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -