简体   繁体   中英

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.

披萨串传递

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.

屏幕转储

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM