Reputation: 5308
Is it possible to use one storyboard setup of a view controller with two view controllers?
Situation: I created one view controller's view in my storyboard. This one lets the user add a new data entry. Lets call it MyNewEntryViewController
. This works fine. Now I need a way to edit my data entries. For that I'd just like to subclass my first view controller and adapt it where it needs to be. Lets call this one MyEditEntryViewController
.
I would load MyNewEntryViewController
using instantiateViewController…
on my storyboard:
MyNewEntryViewController *newEntryViewController = [storyboard instantiateViewControllerWithIdentifier:@"NewEntryViewController"];
That works great.
What if I want to instantiate my new view controller now? Trying the obvious
MyEditEntryViewController *editEntryViewController = [storyboard instantiateViewControllerWithIdentifier:@"NewEntryViewController"];
results in an MyNewEntryViewController
stored in my variable because that's what I had defined in that storyboard.
So, whats the best way to work with my storyboard definition and be able to use two different view controllers? How do you guys do this?
Thanks!
–f
Upvotes: 1
Views: 699
Reputation: 11920
No this is not possible. It is possible to do this with plain old xibs. You can then specify the name of the nib when you initWithNibNamed:bundle:
the view controller.
However, I think it's worth taking a step back. Is it really a good idea to do this? Subclassing view controllers can get messy. View controllers are intended to be self contained units of functionality, which is at odds with subclassing. Unless a view controller is specifically designed to be subclassed then I would avoid doing so. I would suggest that you merge the two view controllers and override setEditing:animated:
.
Upvotes: 2