简体   繁体   中英

Instantiate view controller from Storyboard with a descendant class

I have a generic view controller in my Storyboard, let's say it's class set to MyController class. I also have a view controller class ( MySubControllerA ) which inherits from MyController :

@interface MySubControllerA <MyController>
...
@end

The descendant class is used to overwrite some functions in the parent class.

I can instantiate the main class with this:

[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"MyController"];

But of course this will be instantiated in the class which is given in the Storyboard for the "MyController" identifier.

I want to have an instance of MySubControllerA which accesses everything which was set in the Storyboard and still has it's own functions. Is this possible somehow? Maybe it is not the proper way to solve this problem. Is there a better way to do this? I really don't want to mess MyController with the specific code which I belongs to MySubControllerA .

This is a very common feature request for storyboards, but unfortunately isn't possible at this point. I can tell you from weeks of first hand experience that if you try and hack a way to make this work, you will regret it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM