I am developing an iOS application in Swift.
I want to send data from a view to an other one, using the prepareForSegue function.
However, my target view is preceded by a navigation controller, so it doesn't work.
How can I do this please ?
I am developing an iOS application in Swift.
I want to send data from a view to an other one, using the prepareForSegue function.
However, my target view is preceded by a navigation controller, so it doesn't work.
How can I do this please ?
Let's say you want to send data from the SendViewController to the ReceiveViewController :
Add this to the SendViewController
Edit the identifier segue to "showNavigationController"
this
Of course you can send any other type of data (int, Bool, JSON ...)
A one liner in Swift 3:
In
prepareForSegue
access the target navigation controller, and then its top:From the target controller you can access its view and pass data.
In old - now obsolete - versions of Swift and UIKit the code was slightly different:
Here is the answer for Swift 3:
Complete answer using
optional binding
and Swift 3 & 4: