iOS - Container components in different storyboard

1.1k views Asked by At

I want to make a container which will be in a single storyboard and each component view will be in different storyboard. For example, Container storyboard will be in Home.storyboard and component A and B will be in A.storyboard and B.storyboard respectively. Can anyone guide me how to implement this in Swift?

enter image description here

In this above container component-A and component-B are in the same storyboard along with main container. I want to create different storyboard for both components.

3

There are 3 answers

0
Sazzad Hissain Khan On BEST ANSWER

Finally I got the solution. We need to refactor the components into new storyboard.

  1. Select component A view controller
  2. Xcode Menu -> Editor -> Refactor to Storyboard...
  3. Select a proper name and save it

enter image description here

New storyboard, ComponentA will contain only the component view with a initial view controller mark. New Storyboard will look like below.

enter image description here

2
Irfan On

You can use Storyboard Reference. Storyboard Reference has a name to which storyboard it points and an identifier for UIViewController in that storyboard.

enter image description here

Move Component 1 and Component 2 to separate storyboards. From Object Library drag storyboard references. Attach Segue to Storyboard Reference. Give the name of Storyboard to each Storyboard Reference.

enter image description here

In this way you can separate Storyboards

0
Yun CHEN On

If you want to initialize the controllers from another storyboard, you could do it like this:

    let storyboard = UIStoryboard(name: "Storyboard_B", bundle: nil)
    if let aViewController = storyboard.instantiateViewController(withIdentifier: "AViewController") as? UIViewController {
        //do something about aViewController
    }

And in Storyboard B you need to set identifiy of ViewController:

enter image description here