Canonical way of loading compound UI components from a NIB into some other UI?
Canonical way of loading compound UI components from a NIB into some other UI?
- Subject: Canonical way of loading compound UI components from a NIB into some other UI?
- From: Luke Evans <email@hidden>
- Date: Wed, 5 Dec 2007 14:45:22 -0800
Hi,
I've been scratching around to find the _right_ way of loading some
compound UI from one Nib into a view within another Nib. In other
words, I wish to define a compound view hierarchy as a 'custom
control' and then load this into the location represented by a custom
view in some other Nib, such as in a window.
So, lets say I have a my compound control hierarchy, consisting of a
scroll view at the top, which then contains a number of other views.
These are all stored in a Nib called ScrollingControls.nib. Now, in
my main Nib, I might have a NSWindow and I wish to place a custom view
within this window that will define the location of the root view in
my ScrollingControls hierarchy.
It seems to me that there are a number of gotchas, or at least
'inelegance' (or maybe just work!!) in how I would have to go about
this.
1. If I choose to make the placeholder custom control in my NSWindow
into an actual instance of the some top-level view class in my
ScrollingControls (i.e. in this case it would be natural for this to
be the scroll view), then I have to make this root view in
ScrollingControls be a special case - it would need to be a subclass
of NSScrollView that knows how to load the remaining part of the
compound view from a Nib file - yet this view itself would NOT reside
in this Nib. This has the right encapsulation (the subtree that is
loaded is the business of the root of the 'control' itself), but I
dislike the asymmetry of having to have the top level view exist
outside of the rest of Nib that defines the complete view hierarchy I
want.
2. If I choose to have ALL the ScrollingControls view hierarchy,
including the top level NSScrollView exist in ScrollingControls.nib,
then I cannot see how to elegantly make the placeholder custom view in
the NSWindow automatically load the view subtree from
ScrollingControls.nib and replace the placeholder view. There are
certainly various workarounds that come to mind, such as having a
special NSView subclass in the NSWindow, which does the requisite
loading of the entire ScrollingControls view tree, and that then
performs a "replaceSubview", to substitute itself with the intended
top of the view hierarchy at that point (i.e. the NSScrollView). This
sort of thing seems somewhat awkward however.
So, in a nutshell, I'm looking for the canonical pattern for loading a
view hierarchy from a Nib into a placeholder custom view, without
having to add an extra (essentially spurious) view layer to do this
loading. I've hunted around for some code to demonstrate the right
pattern for this, but most examples deal with loading a single custom
view (without an attendant hierarchy) .
At this point, it seems to me that I cannot avoid having to break the
symmetry, and having the root control that is referenced from the
placeholder custom control be different to the rest of the hierarchy
loaded from Nib (which is what it has to control in it's
awakeFromNib). Yet, it also seems to me that a number of items in the
Interface Builder palette are compound (such as the NSCollectionView),
and this is the behaviour that I'd like - to be simply able to include
a subtree of views directly into some UI. Maybe there's some jiggery-
pokery going on in the case of Interface Builder plug-ins to achieve
this, and I certainly don't want to have to go to the bother of
creating a plug-in to achieve what I want. I'm hoping I'm missing
something simple here!
-- Lwe
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden