Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing data using delegates between viewcontrollers without any navigation controller connection

There are many examples of passing data between two view controllers, where one view controller navigates to another view controller.

But is it possible to pass data using custom protocols & delegates between view controllers that are not connected by navigation controller?

So, an example could be: Three view controllers namely are, A,B,C. A navigates to B, and Bnavigates to C. I know how to pass data between A & B using custom protocols & delegates. But can we pass data between C & A. Thus A can be C's delegate and thereby can receive data from C. Is this possible?

Any help would be appreciated.

like image 962
footyapps27 Avatar asked Oct 06 '12 06:10

footyapps27


People also ask

How do you pass data from one viewController to another using segue in Swift?

Pass Data using Seque. After outlet is connected to respective viewController, select Enter Last Name button and then CTRL + Drag to NextViewController(i.e, FirstViewController) for showing the viewController from LandingPageViewController. This lets you set what kind of segue you want to use.


2 Answers

One way is use delegates for backward passing of data

Refer simple-delegate-tutorial-for-ios link for passing data from C to A controller.

Check basic-delegate-example link.

Another way is by posting notification. for backward passing of data

Check Comunicate-Two-Views link.

like image 177
Paresh Navadiya Avatar answered Sep 21 '22 04:09

Paresh Navadiya


You can use some singleton class and implement delegate protocol in it. So you will have opportunity to pass data between any view controllers.

like image 22
Anton K Avatar answered Sep 18 '22 04:09

Anton K