Storyboard and subclasses

I am trying to create a hierarchy of views using storyboard and subclassing. The idea is to bind the screen to a base class (which in turn is a subclass of UIViewController

course) in the storyboard and instantiate the subclass as needed. The subclass always has the same layout, the main difference is in the function viewDidLoad

. If I call self.storyboard?.instantiateViewControllerWithIdentifier("menu")

, I always get an instance of the base class, even if I add as SubClass


Is there a way to instantiate the subclass the way I want?


source to share

1 answer

No, you cannot do this with a storyboard. You always get an instance of the class that is specified in the storyboard.

Create xib instead. Put your view hierarchy in xib and set the File Owner class to the base view controller class.

Then, in code, instantiate the specific view controller subclass you want, and make all subclasses loadable with the same xib.



All Articles