Re: Quick question about adding an NSPanel
Re: Quick question about adding an NSPanel
- Subject: Re: Quick question about adding an NSPanel
- From: Graham Cox <email@hidden>
- Date: Thu, 23 Apr 2009 10:36:57 +1000
On 23/04/2009, at 10:19 AM, Chris Goedde wrote:
I have a quick question about adding an NSPanel to an app. I'm
following Hillegass's book, so I have a separate controller and nib
for the panel. I added an IBAction (showSettingsPanel:) to my main
app controller and hooked it up to the Preferences... menu item.
Works great.
This isn't actually a preference panel, though, and I want the panel
to open when the app launches so I added the line:
[ self showSettingsPanel: self ];
to the end of the awakeFromNib method of my main controller. Also
works great, with one tiny exception. In both cases the panel has
focus (either when opened from the Preferences... menu or at app
launch). When the panel is opened from awakeFromNib, however, the
main window has a light title bar, as if it's not frontmost. That's
not the case when the panel is launched from the Preferences...
menu. So my questions:
(1) Why does it make a difference how showSettingsPanel: is called?
(2) Is there a better way to do what I want to do?
I'd suggest using the main controller's -awakeFromNib method to open
the panel is going to be too early. Instead, implement an application
delegate (can be any object, wired up in IB in the MainMenu.xib/nib
file) and implement -applicationDidFinishLaunching. That should ensure
that everything is truly ready to go.
Also, ensure that the panel's 'visible at launch' flag is unchecked in
IB. This can give the impression that things worked when they weren't
really triggered by your controller.
Code for showSettingsPanel: below (it's very simple, basically
straight from Hillegass).
Thanks.
Chris
- (IBAction) showSettingsPanel: (id) sender {
NSLog(@"In showSettingsPanel.");
if (!settingsController) {
settingsController = [ [ SettingsController alloc ] init ];
}
[ settingsController showWindow: self ];
}
I assume that the controller is supplying the nib name internally? You
would normally pass it to initWithWindowNibName: though this isn't a
hard and fast rule.
Otherwise it looks fine - try opening the panel slightly later, I
reckon that's your problem.
--Graham
_______________________________________________
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