简体   繁体   中英

Creating and loading Views with another UIView in the Storyboard in Xcode

I have a storyboard with multiple UIViews .

Inside one of my UIViews I add additional sub-views. I essentially drag and drop UITableViews , UIViews etc inside the same UIViewController . See the screenshot below:

恐怖的景致

How can I create these views as separate entities of the storyboard but then.. load them into a particular UIView ?

Maybe you want to use a container. You can embed another UIViewController in a container via right click -> embed -> drag to desired UIViewController You can even use this UIViewController in multiple containers this way (reusing).

The traditional way to do this would be to subclass the UIViews you want to reuse and declare their interfaces as separate xibs. Then initialize them in your ViewController and then add/position them to the base UIView with addSubview:

See this SO answer for more of an explanation. https://stackoverflow.com/a/12880151/902730

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