Romit Kumar
Romit Kumar

Reputation: 3300

How to reuse same view controller in multiple container view in swift?

I have a container view in a view controller (lets say A) with an embed segue to a view controller (lets says B) which is in the same storyboard. Now the requirement is I have to use this same embedded view controller B in another container view in view controller C which is in different story board. Is it possible to reuse view controller B in multiple container views ?

Upvotes: 3

Views: 2734

Answers (2)

Eman Harout
Eman Harout

Reputation: 536

1) For view controller B, add a storyboard identifier

enter image description here

2) Add a container view inside view controller C enter image description here

3) Delete the view controller that is embedded to View Controller C

4) Add a "Storyboard Reference" next to view controller C, then drag from the container view inside view controller C to the storyboard reference and create an "Embed" segue

enter image description here

5) Select the storyboard reference and set the "Reference ID" to match view controller B's identifier. Also make sure "Storyboard" has the name of the storyboard that view controller B is in.

enter image description here

Upvotes: 4

NF Lee
NF Lee

Reputation: 482

You can drag a Storyboard Reference in that different storyboard, and set it's Storyboard and Referenced ID properties to the view controller B.

Upvotes: 0

Related Questions