Jevon Cowell
Jevon Cowell

Reputation: 411

How to pass Data to Another Viewcontroller?

Unlike other questions, the destination view controller is not being Segued to directly. Instead it goes like this A -> B -> C -> D-> E

With Data from A,B,C, and D are passing into E. How do I pass data for view controllers that are not connected at all by Segues?

Upvotes: 0

Views: 89

Answers (2)

nayem
nayem

Reputation: 7605

You can follow the MVC pattern. Create a model class and store data to it's object from view controller to view controllers, meaning, fill that model object with different different data from different different view controller. Then when you need to get data, just use that model class. You can use singleton pattern here.

Another way is, you can create reference of one view controller in another view controller. Then you will be able to access the properties of that view controller (that is referenced) in the containing view controller. This goes on and on.

Upvotes: 1

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726987

Follow the Model-View-Controller approach: make a model object that stores data coming from A, B, C, and D before they segue away to the next view controller; at the end of the chain of segues the model will contain data from all four controllers.

At the point when you reach E, its data is stored for it in the model object; it can take it from the model for display.

Upvotes: 3

Related Questions