Answer the question
In order to leave comments, you need to log in
How to reuse View Controller in project using storyboard?
Understood using the standard Master-Detail Application template. Tried to reuse the Detail Scene (DetailViewController) for the purpose of adding a new object. I created a new class, inherited it from DetailViewController, I call the controller in the insertNewObject method, the controller is displayed, but for some reason the parent DetailViewController is displayed (I looked in the debugger, it is the parent class that is used).
Maybe he did something wrong? Or do you still need to create a new scene?
The project can be viewed here: https://github.com/pchelnikov/DrinkMixer
Answer the question
In order to leave comments, you need to log in
You won't be able to do that. Storyboard always loads the class specified in the properties. And even attempts to play around with the runtime do not give any effect: I tried to override initWithCoder and return the heir class. The application crashes with a note that a different output class is expected. Those. after loading the storyboard checks that everything is in order...
What can be done to solve your problem:
- create a view for the viewController with the code (-loadView), i.e. abandon Storyboard. Subjectively, not the best solution.
- In the storyboard itself, duplicate the viewController, specifying the desired class for it. The fastest solution, but you will have to maintain essentially two identical views. If later you need to finish the project, then you will be very happy :)
- use xib for such duplicate viewControllers. As far as I remember, initWithNib will allow you to correctly load the view into the heir class. Not sure about this, really...
- make the Add view controller a container containing a DetailController. Those. Load detailController from storyboard and add it via addSubview to AddViewController. Or another perversion from the same opera, pull out the view itself from this loaded DetailViewController, set outlets and actions correctly and kill the loaded view controller. It happened to me, but it's all from the evil one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question