2

I've just begun learning iOS programming and do not seem to understand the difference between these two terms.

I've been learning about container views and the apple documents constantly refer to a 'container view controller'. However, I see no class called UIContainerViewController. The storyboard lets me create a specific type of view known as a container view by the means of drag and drop and a standard view controller is created automatically with the creation of this container view and an embed segue is attached.

1 - Is this newly automatically created view controller the container view controller, since it looks like it is responsible for handling the content displayed in the container view that I just created?

2 - or is the original view controller which contains the container view called the container view controller?

3 - The apple document defines a container view controller with this statement - "A container view controller contains content owned by other view controllers." I don't quite understand what it means. Could someone explain it to me?

If there's any additional information required, please leave a comment and I will edit my question to include it.

jscs
  • 63,694
  • 13
  • 151
  • 195
sosale151
  • 360
  • 2
  • 4
  • 19

2 Answers2

2

To answer my own question a bit more systematically,

1 - The newly created view controller is not the container view controller. It is to be treated as an independent view controller. The embed segue specifies precisely that, a segue from the original view controller to the new one. However, the container view is still part of the old view controller and only indicates which other view controller's views will be displayed there.

2 - Yes. This is because the original view controller contains the container as a view. It is ultimately responsible as to choosing which other view controller's views is displayed in the container. Hence it performs the duties of a controller for that container.

3 - "A container view controller contains content owned by other view controllers" : This definition is now made clear. The original view controller displays views that are actually part of (owned by) an other view controller. Hence, as per the definition, the original view controller is the container view controller, having the newly created view controller as the child view.

sosale151
  • 360
  • 2
  • 4
  • 19
0

In short, a container view controller lets you put view controllers inside other view controllers. the storyboard just provides you with a convenient tool that will cause a view controller to be placed in another view controller automatically. if you were to do it in code, you would need to create both view controllers and remove the view of the one vc and place it in the other, all the storyboard is doing is saving you that hassle.

Fonix
  • 11,447
  • 3
  • 45
  • 74
  • But when done via storyboard, let's say I create a new project and there is a default view controller. I create and place a container view inside the default view controller and a new view controller for the container is created automatically and an embed segue is attached, which is the container view controller - the original default view controller that contains the container view or is it the new automatically created view controller? – sosale151 Feb 12 '15 at 06:40
  • the newly automatically created one, the grey one in the original vc is just a placeholder, to show you where it will be in the original vc (but i guess the original vc is sort of a container vc since it contains the child vc, bit of a language break down here) – Fonix Feb 12 '15 at 06:46