Multiple Views in Same Container View Using Storyboard

10,227

Solution 1

Please have a look at this tutorial: How to use a 'Container View' in iOS?

The overall idea is shown in the image.

enter image description here

Solution 2

It will be much easy to design your UI if you use container views.

Add the container view for all your child views. Create properties for all the child container views in your main View Controller. Design the child views with in the container view controller. Apply business logic in your main view controller to show and hide the child views accordingly.

Solution 3

Generally, you don't need to create separate xibs for each child views (technically, we can draw all view controllers on the same storyboard).

With the hide and show issue, make the child views as IBOutlet, and then let your code to decide which view should show and which one should hide.

Solution 4

It will be better when add and remove subviews instead of hiding and showing.

In same ViewController you can use addSubView: to add and removeFromSuperView to remove views

Share:
10,227
Kiran Thapa
Author by

Kiran Thapa

@static NSString *job = @"iOS Developer"; @static NSString *passion = @"Observing good designs.";

Updated on June 30, 2022

Comments

  • Kiran Thapa
    Kiran Thapa almost 2 years

    I have a viewcontroller with a background image and title header. This view remains same most of the time. And I have different child views that i will be showing and hiding inside this viewcontroller.

    How can i achieve this using storyboard?

    1. Do i have to create separate xibs for each child views?
    2. Or do i create individual views inside the same view controller and hide and show them as needed?

    Or is there any other elegant solution?

    Thanks.