views:

42

answers:

1

I have some UI elements that will share common parts with other UI elements. They correspond to model objects in an inheritance hierarchy.

As an example let's say all Layers can be toggled on/off. All WaveLayers are Layers which additionally define a .wav filename. And there is a specific concrete subclass of WaveLayer called GroovyLayer which requires additional parameters.

Visually I'd like to have a long panel where the top section holds the general Layer UI, the next section holds the WaveLayer-specific UI, and the last section holds the GroovyLayer-specific UI. There may be like 10 or so concrete subclasses, each which share the same top sections corresponding to Layer and WaveLayer.

How should I set this up in InterfaceBuilder? Do I start at the top (with a placeholder for the subclass stuff) or at the bottom (with placeholders for the parent classes' stuff)? How should I go about setting up these placeholders in InterfaceBuilder and substituting in the right NSViews at the right times?

I've got this sort of thing to work by using a blank "custom view" in IB and tying it to an outlet in my controller class, and then substituting that view with another view tied to my controller from elsewhere in another NIB, but that seems unelegant, as my controller then carries both "old view" and "new view" members...

A: 

Lay out the views however you wish. Then select the custom view that represents your subclass and set its class name in the inspector.

As to whether to load the views from separate xib files, I think that's overkill here. From your description these views are always visible together, so you gain nothing but complexity loading them from individual files.

The trick you seemed to be missing was setting the class name of the custom view to that of your subclass.

Joshua Nozzi
uh, so shouldn't the custom view from my subclass be in a separate nib? where else would it come from?
evilfred
You'll have to give a lot more information about how your project's xibs are set up for advice on how best to separate them. Your custom views don't *have* to be in a separate xib as that of their parent view (superview), though.
Joshua Nozzi
I will have lots of different classes, like 10, and I don't want them all in the same NIB, I would prefer them to be in separate NIBs. But I want all 10 types of objects to share some common UI elements, which I don't want to copy/paste into each.
evilfred
I'm sorry but the topic now looks like it doesn't match the subject (question). You may need to restate your goal or separate the questions.
Joshua Nozzi
from my POV it's the same question... i guess it wasn't complete. added some info to the question.
evilfred