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

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -