Re: A bit confused about NSView instances in Interface Builder
Re: A bit confused about NSView instances in Interface Builder
- Subject: Re: A bit confused about NSView instances in Interface Builder
- From: Scott Ribe <email@hidden>
- Date: Tue, 03 Oct 2006 22:28:14 -0600
- Thread-topic: A bit confused about NSView instances in Interface Builder
When you instantiate the view, that means that when the nib file is loaded
an instance of that class will be created. When you drag a control into the
window and set its class to A, that means that when the nib file is loaded
an instance of A will be created and placed in the window. Notice what's
missing? No connection whatsoever between the two--that's what you're
missing.
Instantiating like what you tried for A is useful for controller and
data-source kinds of classes, which typically other classes reference via
outlets which you hook up in IB. Suppose you have several complex panes or
groups in one window. Rather than putting all the controller logic in a
single subclass of NSWindowController, you could make several
sub-controllers for each pane, and your main controller would have IBOutlet
MySubControllerClass1 * subcontroller1 and so on, and you'd make file's
owner the class of the main controller, instantiate each subcontroller, and
control-drag from the file's owner to each subcontroller, hooking up the
subcontrollerx outlets to the instantiations. You might also hook various
user interface items up to the subcontrollers as targets or delegates,
instead of the main controller. You might also have outlets in the
subcontrollers which get hooked up to the main controller, so they can query
it or notify it of updates in the panes.
OK, summary:
1) Instantiation works for any Obj-C class. It just creates an instance of
the class when the nib is loaded.
2) The instance is not worth anything unless you hook up a reference to it
and use it somehow. (Well, perhaps +init or -init or -awakeFromNib could
have some side effect, but that seems unlikely to be a good design.)
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden