How to use a 'Container View' in iOS?
Asked Answered
B

1

38

I have noticed the UI Component in XCode: Container View.

enter image description here

Based on the description provided I would like to make use of it to display a reusable component of my app in several different screens. I have been looking around online to try and find a basic tutorial or some documentation on it, however I havent found anything of use.

Please could someone advise on how to wire this up and make use of it? At the moment it also appears that the container view doesn't seem to resize which is problematic. Any tips on how to enable this would be appreciated too.

Cheers.

Bluenose answered 2/6, 2013 at 16:35 Comment(1)
U
63

Well let's break this into some simple steps:

  1. Drag a container view to the main view of one of your controllers. When you drag the container view, IB will create an embed segue for you and you can resize the container's view by dragging the resize control points as usual. Any changes in the size will be automatically reflected to the view that the segue is pointing to. The idea is that this view will be managed by a different controller, the embedded one. enter image description here

  2. Set your custom subclass as the class of the embedded controller. enter image description here

  3. Now you're good to go. Note that any containers you add will be available through the childViewControllers property on your main controller. enter image description here

This is obviously an oversimplified workflow but it's enough to get you started. For more information on the subject, see Apple's documentation here.

Unmask answered 2/6, 2013 at 17:3 Comment(2)
Great explanation! Link needs to be updated to Apple Documentation.Pulque
totally up-to-date guide for 2017 here: https://mcmap.net/q/17273/-how-to-add-a-subview-that-has-its-own-uiviewcontroller-in-objective-cAntagonism

© 2022 - 2024 — McMap. All rights reserved.