μολὼν.λαβέ
μολὼν.λαβέ

Reputation: 668

How do I pass data from one UIView to a sub UIView?

I'm having a brain cramp for some reason on this. Some already posted questions/answers are outdated or objective-C. I'm not sure if delegate is the way to go?

I have a hierarchy of UIViews.

Pizza String to pass

In phenotypeSunplotView:UIView some data is set, a string. I want to pass a string to another class of UIView which actually does the plotting, SunplotView:UIView

For example, I want to pass the string "Gorgonzola" to the class that plots the circle, SunplotView:UIView and plot the string next to the circle.

screendump

Upvotes: 0

Views: 609

Answers (1)

Duncan C
Duncan C

Reputation: 131398

As a general rule, you don't. Views are not data storage objects. They are the "View" in the Model/View/Controller design pattern.

Instead, you set up the view controller to install the data in both places. Give your view controller outlets to all views that it needs to change.

If a view is an input field (like a UITextField for example) then you add an action or delegate method in your view controller that gets called when the user enters data. Then you collect that data and copy it to any other views that are appropriate. The view controller mediates as needed to implement your app's logic.

Upvotes: 3

Related Questions