Re: IBOutlet to same control in different nibs
Re: IBOutlet to same control in different nibs
- Subject: Re: IBOutlet to same control in different nibs
- From: Ken Thomases <email@hidden>
- Date: Thu, 17 Jul 2008 18:52:44 -0500
On Jul 17, 2008, at 11:42 AM, Trygve Inda wrote:
I am creating a System Pref Pane that has one window for each physical
monitor, very similar to the Displays prefpane. Like the Displays
prefpane,
on the Main monitor there will be the System Pref window with 4 tabs
(A B C
D), but on other monitors, the window will only have tab A.
I'd like one controller class to handle the controls in tab A
regardless if
it is in a main or aux window. I'll have one instance of this class
for each
screen, one of which will be handling the "main" screen.
OK.
So I have 2 nibs: my main prefpane nib that is loaded by the System
Preferecnce app (and has tabs A B C D), and an "AuxScreen" nib with
tab A
which I am loading manually.
Duplicating tab A smells fishy. I can imagine two solutions:
1) Use one nib for all screens, but remove tabs B, C, and D from all
but the main screen.
2) Put tab A as a free-floating view into its own nib. Load that nib/
view and insert it into the windows for each screen. In this case,
the tab A logic would go into a custom subclass of NSViewController
which would be used to load and own the nib.
Currently I have one appController class that handles all the action
in the
main window and a "auxScreen" class to handle the auxScreens.
Obviously
there is a lot of code duplication in these two classes.
Even if you don't use either approach I outlined above, you should
still have one class which holds the smarts which are common across
the windows. If one window has special additional smarts above and
beyond that, you can make its controller a subclass of the common
controller. Or, you can put the additional smarts in a separate class
which will cooperate with the common controller class (somewhat like
how NSApplication cooperates with its delegate to customize its
functionality).
How can I build one class to handle both???
You sound very vexed by this question, but the answer seems self-
evident to me. You just do. It's totally up to you what your classes
do and how you use them. Nobody's standing in your way.
In that class there will be something like: IBOutlet NSSlider
mySlider;
but this has to "point" to a functionally identical control in two
different
windows, in two different nibs.
Outlets are connected up quite dynamically when nibs are loaded. If
you connected an outlet of File's Owner in your nib, and you specify
an instance of you class as the nib owner when it's loaded (this is
implicit if you let the NSWindowController machinery load the nib),
then that outlet of that instance will be connected.
Can a single class have an IBOutlet that goes two different (though
functionally identical) places?
Although a class defines the outlet, it will be instances which "have"
the outlets in this sense. Outlets are just instance variables which
are pointers to objects. Tagging them with "IBOutlet" is only a means
to inform Interface Builder about them, but doesn't change them
functionally.
So, of course, it's perfectly natural that each instance may have a
different pointer to a different object.
Cheers,
Ken
_______________________________________________
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