2

I'm interested in building a slide out sidebar for a view controller, and I've done a lot of reading on how to implement it. This tutorial, as well as virtually all the others go over creating child view controllers, which seems like a great way to go about it. However, it's always done in code for examples.

This post goes over how to create container view controllers in the Storyboard, but it left me confused how exactly container views work in the Storyboard, and there seems to be little in the way of explanations online.

Finally, this post went over how to implement a slide out menu with container view controllers and a Storyboard. Sounds perfect right? Well, in reading it I was confused how the author seems to use multiple container views. I thought there was supposed to be one that encompassed all of the subviewcontrollers. Is it implemented correctly in that post?

Basically, I'd love an explanation on how to implement multiple view controllers using container view controllers via the Storyboard. It's my understanding from the first tutorial that you have the view controller that contains everything, and then add view controllers to that container and then they all work together via delegates. Achieving this in Storyboards is leaving me scratching my head.

Doug Smith
  • 29,668
  • 57
  • 204
  • 388
  • A container view in the storyboard does the same thing that adding a child view controller and its view does in code -- it adds the controller as a child and adds its view as a subview with the size and position of that child view defined by the container view's frame. It's not clear from your question how many controllers you're trying to add. Why do you want more than one child? Do you want multiple menus? – rdelmar Dec 12 '13 at 02:09
  • This does not use storyboards, but this what I have used. https://github.com/picciano/Slide-Navigation-Prototype – picciano Dec 12 '13 at 02:12
  • @rdelmar I sort of want multiple menus. An extra one to drop down vertically when a button is pressed. And in code, you add view controllers to a containing view controller. I guess I'm confused in that it seems with Storyboards you're adding to a view? Or does adding that container view transform it into a container view controller? And if I'm adding multiple, how do I add the container view? Do I make it encompass the right or left? Or do I add multiple like in the third link (which again, it seems weird to have multiple containers)? – Doug Smith Dec 12 '13 at 02:22
  • @picciano I appreciate the link. I've found a few libraries that work for what I have in mind, but I'd really like to implement this myself for understanding purposes more than anything. – Doug Smith Dec 12 '13 at 02:23
  • In code you add a controller as a child, but then you also add that controller's view as a subview -- you have to do both. That's what happens in the storyboard as well. The container view just defines where that subview is going to be added, but you see that you also get an embed segue to a view controller. Have you dragged in a container view in IB to see what happens? – rdelmar Dec 12 '13 at 02:26
  • @rdelmar So if I want multiple sidebars for instance, do I just drag multiple container views? If so, then why does the second link talk about getting around the limitation and how to add multiple children? Why wouldn't they just add multiple containers? – Doug Smith Dec 12 '13 at 02:52
  • Here's another example: http://stackoverflow.com/questions/8198698/linking-child-view-controllers-to-a-parent-view-controller-within-storyboard What are these people trying to solve that multiple containers does not? – Doug Smith Dec 12 '13 at 05:04

1 Answers1

1

Adding a container basically adds a child view controller and its view to the main controller. I think you are not clear on two things here. First, each container can be linked to only 1 controller/view pair. So, if you want to have more than one child controllers, you must have more than one containers. Secondly, communication between parent and child controllers is handled by 'embed segues', not by delegates.

Roshan
  • 1,937
  • 1
  • 13
  • 25
  • So it's delegates in code, but embed segues in Storyboards? And what's the second example talking about when describing a technique for multiple child view controllers? Why wouldn't they just add multiple containers? – Doug Smith Dec 12 '13 at 02:24