Re: File's owner, outlets and methods
Re: File's owner, outlets and methods
- Subject: Re: File's owner, outlets and methods
- From: Michael de Haan <email@hidden>
- Date: Thu, 13 Aug 2009 19:32:56 -0700
On Aug 13, 2009, at 6:36 PM, Ken Thomases wrote:
On Aug 13, 2009, at 4:24 PM, Michael de Haan wrote:
[
**Very** briefly, the set up is as follows.
AppController has an outlet (IBOutlet NSPanel *aboutWindow) and a
method (-(IBAction) showPanel: (id) sender;)
....snip.....
One is that the About Window's target is established in the
MainMenu.xib ( ie About NewApplication is connected to the method
showPanel).
The About _menu_'s target is established in the MainMenu.xib. The
About _window_ is not known in the scope of this xib.
Of course...stand corrected. That's what I meant but syntax is
important :-)
Secondly, in the About.xib the File's owner is set to the
AppController AND File's owner "aboutWindow" outlet is now pointed
to the NSPanel object.
I am assuming that this second action is used in the method of
showPanel, where I assume? AppController's outlet is utilized?
Not as you've written the showPanel: method below.
As I drove home I got to thinking ( that's what a good thunderstorm
will do!). I in fact disconnected all references ( by this I mean
IBOutlets in AppController and opened the connection between File's
owner and the NSPanel . It still worked and then it dawned that the
outlet was there **if** I needed to send a message **after** the Nib
was loaded. So, reconnected all, and changed the title of the Panel
after the "BOOL successful = [NSBundle loadNibNamed: @"About" owner:
self];" call, and it suddenly all made sense.
What confused me, as it has done a number of people following this, is
the advice given by Hillegass to set up an outlet in the AppController
class and use the NSBundle class to load the nib. Understandably, I
think most of us expected, therefore , that this outlet **would** play
a role in this setup, but , clearly, I think in this case, it is being
set up for later use, I suspect.
An outlet is a property of an object. It's often backed by an
instance variable as its implementation.
Once you connect an outlet to an object in the nib, this connection
is recorded as data within the xib/nib. Later, when that nib is
loaded, Cocoa's nib loading machinery reestablishes the connection
by setting the property on the object. In this case, the outlet is
on File's Owner which, during nib design, is a proxy for an actual
object which is supplied when the nib is loaded. It's the property
on this actual object which gets set during nib loading.
So, after that nib is loaded, the aboutWindow property of your
AppController object has been set to refer to the panel that was
reconstituted from the data in the nib.
I think I finally get "File's owner" :-) So, if I understand you
correctly, having set File's owner to the appropriate class ( in this
case AppController) I set the appropriate **proxy** outlet of File's
owner to the object ( in this case NSPanel instance) and when the
Nib is loaded, AppController's IBOutlet gets set to the NSPanel
instance, allowing me to send a message from AppController ( set title
etc) during run-time.
-(IBAction) showPanel: (id) sender
{
BOOL successful = [NSBundle loadNibNamed: @"About" owner: self];
}
2) Consider what happens if you invoke the About menu when the About
panel is already showing. In fact, try it.
Yep..see above :-)
You probably only want to load the nib once, if it hasn't already
been loaded. After that, you only want to reuse the panel that was
loaded that first time. You just have to tell it to show itself.
Try to figure out how that would work. If you have trouble, feel
free to ask again.
Ken...this may seem like a small thing to you, but this little
exercise, with your help and the others who have answered has given me
some good understanding I did not have before.
Much appreciated.
_______________________________________________
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