Search code examples
c#iosxamarinxamarin-studiouicontainerview

Understanding of how to use "Container View" in iOS Designer


One can add a Container View on an existing view with the help of iOS Designer. A container view is placed on the existing view with an embed segue to a new added view controller. The new added view controller is responsible for the content of the container view.

One problem is that you can't change the embed segue or create a new embed segue. The only way is described here. But how do you use that? I saw an example by exchanging the view controller in the container. That's not what I want. I want to display multiple view controllers in one container, but I only get this managed by code.

So for what use cases is this Container View element?


Solution

  • "Container View" is a bit of a misnomer in this case. It doesn't actually contain anything.

    What it does is place a frame onto the "parent" view controller's view to show you where the contained view will appear.

    By doing this you can then use constraints on it and design around it etc...

    If you want multiple separate view controllers to be contained in a parent view controller then you can always just add additional container views and set them up with new container segues.

    But I think there might be a better way to achieve what you want to do.

    Update

    OK, from what it sounds like you want to have Table 1 on the screen. Then the user selects something and then table 2 is shown. Then Table 3. etc...

    To do this I would do the following...

    Make your "container segue" point to a navigation controller. Not to a table.

    Then the root view of your navigation controller will be table 1. Then you can use normal "push" segues to go to table 2 and table 3. You can even put these into the designer and use segues.

    So like this...

    [] = view controller
    () = segue
    
    [Parent]-(embed)-[Navigation Controller]-(root)-[Table1]-(push)-[Table2]-(push)-[Table3]
    

    That should do what you want.