Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Container View in iOS 5 SDK?

Tags:

xcode

ios

ios5

I'm confused that why and when we need to use the container view? and how can we instantiate a Container View by code?

like image 273
William X Avatar asked Nov 13 '12 03:11

William X


People also ask

What is container view iOS?

Unlike a content view controller that displays your app's data, a container view controller displays other view controllers, arranging them onscreen and handling navigation between them. A container view controller is still a view controller, so you display it in a window or present it like any other view controller.

What is a container view controller?

Container view controllers are a way to combine the content from multiple view controllers into a single user interface. Container view controllers are most often used to facilitate navigation and to create new user interface types based on existing content.

What is a container in Swift?

Essentially, container view controllers are subclasses of UIViewController that are dedicated to managing other view controllers, and presenting them in some fashion - just like how UINavigationController presents its children in a navigation stack and manages a navigation bar.


1 Answers

The container view is a view that you can drag into one of your view controllers that you already have in your storyboard (we'll call this viewControllerA). You automatically get a view controller connected to this view via an embed segue. This new view controller has its frame set, so that it's the same size as the container view -- if you resize the container view, the controller will automatically resize as well. So, if you want, you can drag in multiple container views into viewControllerA, and each will have its own view controller. In code, if you need to access these embedded view controllers, they can be accessed from viewControllerA.childViewControllers -- that will give you an array of any embedded view controllers that you have.

There is a discussion of these container views in the WWDC 2012 Session Videos video called "Adopting Storyboards in Your App".

like image 101
rdelmar Avatar answered Oct 05 '22 23:10

rdelmar