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;)

]

So, there are really 2 things happening here?

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.

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.

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.

Now, some properties will be used by the framework because the framework was designed with them in mind. For example, the delegate property of the application object. Hooking this outlet up in a nib has automatic effects, because the framework makes use of the application delegate in various ways.

However, properties you define yourself typically won't be automatically used by the framework. So, setting up a custom outlet such as aboutWindow in a nib doesn't have secondary effects. It only has the primary effect of setting that property on that object as the nib is loaded. From there, it's up to you to make use of that value in whatever code you write.


-(IBAction) showPanel: (id) sender
{
        BOOL successful = [NSBundle loadNibNamed: @"About" owner: self];
        
}

Hmm. As you report you've got things working, I'm guessing the panel in the About.xib is set to Visible At Launch. So, the very act of loading the nib causes the window to display. If you've also set it to Release When Closed, then it will properly clean itself up when it's dismissed.

However:

1) This doesn't make any use of the aboutWindow outlet of the AppController object. So, there would be no need to set that outlet up and connect it.

2) Consider what happens if you invoke the About menu when the About panel is already showing. In fact, try it.

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.

I'm not familiar with the Hillegass book, so I don't know if you've gotten to NSWindowController's, yet. I'm guessing not. At some point, you will. It should make clear that you should probably use NSWindowControllers (or subclasses thereof) as File's Owner for nibs which contain windows or panels. That has some important benefits for managing the resources of the nib. I won't get into that now. :)

Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to