views:

23

answers:

1

All of my application's pages share the same layout and a set of UI elements, which I've been trying to make a reusable component out of.

I've gone the subclassing road, making an "abstract" subclass of UIViewController to hold the base logic for navigation, and a nib file laying out the UI.

I've spent some time unit-testing the base class, which works as expected, but ran into inheritance related issues when I started actually subclassing it.

I won't go into details, since I'm thinking this was actually a bad idea, and composition is the way to go, but I thought I'd ask before wasting any more time...

What would be the best approach here ?

Cheers

A: 

The easiest way is to use a base class, as you've done. Without any details, it's hard to help you further.

If they all use the same layout, couldn't you just make it one class?

tc.
Thanks this made me look into it a bit further, and I figured out how to reuse a base nib file, by calling the following method in the base class' viewDidLoad : [[NSBundle mainBundle] loadNibNamed:@"BaseNibName" owner:self options:nil];
julien
Just make sure the base nib doesn't set "view"...
tc.
hmm are you sure about this bit, I have some unit tests that fail oddly, so I tried it, but now I get : loaded the "MyBaseViewController" nib but the view outlet was not set. Tried adding the views from the array one by one too, same issue...
julien