ios - How to pass data from view controller to a navigation controller and then to another view controller? -
i have data view controller want pass view controller, have set present modally, have navigation controller between them. how pass data first view controller through navigation controller second view controller?
i have code in first view controller:
override func prepare(for segue: uistoryboardsegue, sender: any?) { if segue.identifier == "presentpopup" { let destviewcontroller = segue.destination as! navigationviewcontroller destviewcontroller.mydata2 = mydata } // new view controller using segue.destinationviewcontroller. // pass selected object new view controller. }
then code in navigation controller:
override func prepare(for segue: uistoryboardsegue, sender: any?) { let destviewcontroller = segue.destination as! secondviewcontroller destviewcontroller.mydata3 = mydata2 }
but doesn't work.
you can use in first viewcontroller:
override func prepare(for segue: uistoryboardsegue, sender: any?) { if segue.identifier == "presentpopup" { let destviewcontroller = segue.destination as! navigationviewcontroller let secondviewcontroller = destviewcontroller.viewcontrollers.first as! secondviewcontroller secondviewcontroller.mydata2 = mydata } // new view controller using segue.destinationviewcontroller. // pass selected object new view controller. }
Comments
Post a Comment