Re: Multiple views in a nib file?
Re: Multiple views in a nib file?
- Subject: Re: Multiple views in a nib file?
- From: Graham Cox <email@hidden>
- Date: Mon, 24 Nov 2008 19:32:08 +1100
On 24 Nov 2008, at 6:17 pm, Jean-Nicolas Jolivet wrote:
What I'm trying to do is a bit weird but, it seems to be the only
way I can think of implementing such a concept, anyway I'll do my
best to explain... so I have an abstract class (let's call it
Tools)... basically it just defines some methods/properties that the
subclass should implement (as I said... an abstract class)...
Each subclass of Tools must have a different custom view assigned to
it (i.e. the "Pencil" class, which is a Tool subclass, has a custom
view, the "Paintbrush" class has a custom view etc...), so I added a
"NSView *view" properties to my base "Tool" class.
The problem is, I'm not sure how I can store those custom views and
associate them with their respective subclasses once they are
instantiated. I'm able to do it if each views are in separate nib
files, that way I just add a "nibName" property to my Tool class, so
that every subclass of it has a distinct nib name, I load that nib
and load the only view in it...
however, this doesn't really seems like the ideal way of doing
this... wouldn't it be more practical to save all those views in
only one nib file? But the problem is, if I do it that way I don't
know how to access a specific view from that nib file... I thought
about trying to access it via the "Interface Builder Identity" name
property but apparently this isn't accessible programatically...
Obviously, if I store all my custom views in the same nib file, and
each subclass of Tool has to be associated with one of those custom
views, I can't really set a File Owner to that nib file and define
an outlet to be associated with any of the view since the "File
Owner" could basically be any of Tool's subclasses....
Should I just store each custom view in their respective nib
files??? Or perhaps I'm just looking at this the wrong way?
Any help would be appreciated...
Is the idea that as one selects a tool, a pane is switched to show the
tool's options?
If so, and all the views are in the same window, then I'd put all the
views in the same nib (one window = one nib). Then you can simply have
outlets to each view and install the one you want given the selected
tool. Easier still is to use a tabless tab view and switch the current
tab.
I'd also resist somewhat the idea of each tool having a "view" outlet.
While that seems an obvious way to link a tool with its options, it's
breaking MVC a little bit, though it depends on your app's concept of
a tool of course. I'd have a tool controller that receives the tool
selection and installs the relevant options view. One way I've done
this in the app I'm currently working on is to use a simple naming
convention for the outlets to the views which is related to the name
of the tool. Then I can simply look up the relevant view by taking the
tool's name, building the outlet name from it, then using valueForKey:
on the controller to return the outlet which gets processed further
(by installing the view into the window in my case). It's very
extensible and means that the tool controller doesn't need to know
about all the different tool classes, only that the generic tool has a
name, and that the outlets follow a simple naming scheme.
I can't see any benefit to having each view in separate nibs if this
indeed what you're trying to do - it's an extra level of complexity
that isn't worth the trouble.
hth,
Graham
_______________________________________________
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