Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard - how to make multiple containers embed to the same view controller?

Is there a way for multiple container view's on different scenes to point to one same scene or view controller ? The way I see it, every container has its own embedded scene. What would be the strategy here ? To use the same class on each embedded scene ?

enter image description here

like image 243
the Reverend Avatar asked Nov 26 '25 16:11

the Reverend


1 Answers

You can hook up multiple container views to the "same" embedded view controller. Control-drag from each container view to the view controller and, when the popup menu appears, choose “embed”.

However, I put "same" in quotes because you need to understand what's going on. At runtime, each container view will create a new instance of the embedded view controller, created by deserializing that part of the storyboard once for each container view. They won't all share the same instance. If you want to keep one persistent view controller that you move around from container to container, you need to do that yourself in code.

like image 101
rob mayoff Avatar answered Nov 28 '25 06:11

rob mayoff