3
votes

I'm working on my first iPad application and using Storyboards for the first time.

I've got UITableViewController in my Storyboard that uses "Dynamic Prototypes" for custom cells.

What I want to do is programatically instantiate my UITableViewController subclasses but loading the super view controller from the Storyboard.

This is because I have a single UI but multiple subclasses for specific functionality that I need for each different instance.

This was very easy to do with .xib files, I would write the following code:

MyViewControllerSubClassA *viewControllerA = [[MyViewControllerSubClassA alloc] initWithNibName:@"generalViewControllerNib" bundle:nil];

MyViewControllerSubClassB *viewControllerB = [[MyViewControllerSubClassB alloc] initWithNibName:@"generalViewControllerNib" bundle:nil];

I know I can assign a subclass in the Storyboard editor when clicking on the View Controller but I want to set the subclass programmatically when instantiating.

This seems impossible to do with Storyboards as they are instantiated automatically.

This makes the entire concept of Storyboards seem flawed and not very OO.

If I move the View Controller out of the Storyboard and into a .xib file I lose the ability to use Dynamic & Static Prototypes cells as these are supported only when using Storyboards. Also Apple's documentation basically says use Storybaords from now on.

1
Exactly same problem... Have you figured that out?DanSkeel
No I just had to add the tableviewcontroller multiple times to the storyboard each with a separate class.Camsoft
I finally realized that I don't need any IB, so I just subclassed my VC and inited them both with simple init method...DanSkeel
I guess the limitation I found was that if you want to use the Static Table View cells you can only do them from IB.Camsoft
Same problem here, I'm wondering if we can use initWithCoder...Raphael Oliveira

1 Answers

-1
votes

I would try something like this:

MyViewControllerSubclassA *controllerA = (MyViewControllerSubclassA *)[self.storyboard instantiateViewControllerWithIdentifier:@"myGenericVC"];