Re: Toplevel Objects in NIB files
Re: Toplevel Objects in NIB files
- Subject: Re: Toplevel Objects in NIB files
- From: Vince DeMarco <email@hidden>
- Date: Wed, 3 Apr 2002 09:42:17 -0800
On Tuesday, April 2, 2002, at 05:26 PM, Sherm Pendley wrote:
On Tuesday, April 2, 2002, at 07:32 PM, Nat! wrote:
I asked this before, but under a different subject line, so maybe it
didn't get any attention :)
What I would _really_ like to know is how NSWindowController learns to
know all top level objects in its associate NIBs. This is a trick I
would like to do myself sometimes.
If you really want to do this, basically you do this here.
use the NSBundle method loadNibFile: externalNameTable:withZone:
[NSBundle loadNibFile:windowPath externalNameTable:[NSDictionary
dictionaryWithObjectsAndKeys:[self owner], @"NSOwner", topLevelObjects, @"
NSTopLevelObjects", nil] withZone:[self zone]]
the NSMutableArray (topLevelObjects) will then get filled with all of them.
vince
After the NIB is loaded and the objects in it deserialized, for each
outlet, a corresponding set*: method is looked for in the NIB's owner,
and if it's found, called.
For example, if you've created and connected an outlet named "myButton"
in IB, the method "setMyButton:" will be called when the NIB is loaded,
with a pointer to the object loaded from the NIB.
The Objective-C runtime will generate accessor methods automagically. So,
if no "setMyButton:" method is defined, but a "myButton" instance
variable exists, the value passed to the method call is assigned to the
instance variable. Similarly, if a "myButton" is called, the value of the
instance variable is returned.
FWIW, I don't recall seeing any really good documentation about this -
and I looked hard, because it's very important for supporting
dynamically-loaded NIBs within a language bridge. I figured it out for
CamelBones by coding my proxy class to report the name of each method
asked for with "respondsToSelector:", and then noticed that a call to
"setWhatever:" got generated for each outlet I wired up in my NIBs.
I *think* that this happens in the establishConnection: method of the
NSNibOutletConnector class - but the documentation only says that this
method establishes connections, without saying anything about how they're
established.
Hope this helps!
sherm--
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.