开发者

How do you make a view corresponding to a model subclass that holds view elements corresponding to the parent model class?

开发者 https://www.devze.com 2023-01-15 06:00 出处:网络
I have some UI elements that will share common parts with other UI elements. They correspond to model objects in an inheritance hierarchy.

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 o开发者_JS百科utlet 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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消