Member-only story
Swift 101. Delegates between UIViewControllers
Find more useful articles at www.davidseek.com
Today I would like to answer a question I got quiet often lately. How do you transfer information between UIViewControllers that are connected with a UINavigationController.
This scenario is very common. A typical scenario is the Settings App of the iPhone’s iOS. We navigate from controller A to controller B using a navigation controller, we send information from A to B and from B back to A.
In this article I will talk about the 2 most common approaches. A segue using the storyboard and the init with dependency.
The Keyword: Delegate
The idea with our small test project is that we have an origin controller with two buttons and a label. If we press the “Pick Navigation” button, we will present the TopBottomController using a segue. And on “Pick Presentation” we will present the LeftRightController.
If we press one of the buttons in TopBottomController or LeftRightController, we will dismiss/pop the controllers and send the selection back to the origin controller and present the selection in the label.