I'm trying to pass data between A & C, where A is the first controller and C is the third controller. Now I know how to pass data from A to B & B to A, where you create a protocol in B and create a delegate inside the view controller. That looks something like this.

Now how would I do this with C Controller or even a D Controller. Cause I have a navigation controller, where in controller C I create a new Item and pop to the root view controller. Then I would like to change the UI, but can't seem to figure it out. Would really appreciate the help.

More Detail Explanation

Controller A, login controller which has a sign up button that takes me to Controller B. Controller B, email controller. Controller C, username/name controller. Controller D, password controller. So from controller B, I pass the email to controller C and so on until Controller D. This is where I create the new User. When the new user is created in the Controller D, I pop to the root view controller. Then this is were I would like to perform a segue to Controller E from Controller A, once the new user is created in Controller D. Controller A,B,C,D are all in one navigation controller.

So looking at @bsod and @Caleb answers it seems that I either pass a delegate or a data model between my A-B-C-D controllers?

if you are not keeping any reference when popping. Notification Center with observer is the way to pass the data. post a notification to notification center just before popping view controller, observe the notification in viewdidload of the root view controller.
– Muhammed AzharudheenJan 13 at 5:08

how do you navigate to controller C ? I mean which controller is it's parent
– andesta.erfanJan 13 at 5:08

@andesta.erfan I navigate from B controller to C controller by a show/push segue. A is the root view controller of the navigation controller
– Luis F RamirezJan 13 at 5:42

3 Answers
3

This is a good reason to organize your app around a data model. The app delegate or first view controller can create the model, which should contain the data and business logic for the app. Each view controller passes a reference to the model to any other view controllers it creates, and then you don't have to worry much about passing data between view controllers. If your view controller C or D make some changes to the model, they don't need to be handed back to A explicitly... A just automatically gets the updated data by virtue of talking to the same data model that C or D use.

Here's a concrete example. Let's say you're building an organizer for salespeople. So your data model might be called OrganizerModel, and it'll include a list of customers. You can tap on a button to see all the customer locations on a map, and then you can tap on a particular location on the map to see and edit the customer data. So, how should those changes get communicated back to the rest of the app? Let's imagine that there's a MainViewController that shows the app's main view and lets you access the customer list, supplier list, product catalog, calendar, etc. When you tap a button to look at the customer list, MainViewController segues to CustomerListViewController, and in prepare(for:sender:) it does something like:

So now the customer list controller has access to the list of customers, which is all it needs to do its thing. From there, the user can tap a button to see all the customers on a map, and when that happens the CustomerListViewController segues to a CustomerMapViewController, again doing something like:

So the CustomerMapViewController shows a map, including little icons for each customer, and when the user taps on one of those it segues to a CustomerViewController, which only needs a single customer's record to do everything it does:

Now we've got a situation like your A->B->C->D case, where a view controller several jumps away from the first one is changing some data. But when CustomerProfileViewController makes some changes to its customer, there's no need to send that information all the way back to MainViewController, because MainViewController and CustomerProfileViewController are both using the same data; it's customer is part of the overall model that MainViewController uses.

Thanks @bsod, for taking the time to reply to my question. Can you check at the edited question.
– Luis F RamirezJan 14 at 6:19

From your description, it appears that the ideal solution would be to pass a data object forward from A through D with each controller adding to that object. Once that object reaches D and is completed, you can pass that completed object back to A through a delegate.
– bsodJan 14 at 17:59

You may have other option to do this,
First one: you have to create your delegates from A to B and then again B to C. (If you do not want that your view controller B would appear than animation false would suggested)

Or you can choose create Notification Bus between the ciew controllers
You can use the "NotificationCenter" method for it.Where you define the same observer and receiver in it and you will get the controll of the class where you have define the receiver of that notification.

Please be remove all the notification observer while pushing the new view controller.