Re: 10.4 System Preferences Cannot Find Its Main Window When Launched by a Pane Bundle
Re: 10.4 System Preferences Cannot Find Its Main Window When Launched by a Pane Bundle
- Subject: Re: 10.4 System Preferences Cannot Find Its Main Window When Launched by a Pane Bundle
- From: Michael Ash <email@hidden>
- Date: Thu, 29 Oct 2009 11:38:50 -0400
On Wed, Oct 28, 2009 at 7:18 PM, Grant Erickson <email@hidden> wrote:
> I am working on a preference pane and in order to accommodate differences
> among 10.4 and 10.5 and later without hard-coding widths, I call my own
> [self resizeView] from mainViewDidLoad to adjust the view width as
> appropriate:
>
> - (void) resizeView
> {
> NSRect viewFrame, windowFrame;
> NSWindow * mainWindow = NULL;
>
> viewFrame = [[self mainView] frame];
>
> mainWindow = [[NSApplication sharedApplication] mainWindow];
>
> if (mainWindow != NULL) {
> contentFrame = [mainWindow contentRectForFrameRect: [mainWindow
> frame]];
>
> viewFrame.size.width = contentFrame.size.width;
>
> [[self mainView] setFrame: viewFrame];
> }
> }
>
> Overall, this seems to work well; however, when testing automatic updates
> with Sparkle, I noticed that when Sparkle relaunches the bundle
> ("/Library/PreferencePanes/MyPane.prefPane") using its 'relaunch' binary
> (which in turn uses NSWorkspace), that [[NSApplication sharedApplication]
> mainWindow] returns NULL.
>
> In fact, when I check [[NSApplication sharedApplication] mainWindow] in all
> of:
>
> * initWithBundle
> * mainViewDidLoad
> * willSelect
> * didSelect
>
> it is always NULL. Removing Sparkle from the loop, I can recreate the
> problem using the 'open' shell executable:
>
> % open /Library/PreferencePanes/MyPane.prefPane
>
> Anyone else seen this behavior or developed a reasonable workaround? Perhaps
> registering for and resize on NSWindowDidBecomeMainNotification?
Quoth the docs:
-----
mainWindow
Returns the main window.
- (NSWindow *)mainWindow
Return Value
The application’s main window or nil if there is no main window.
Discussion
This method might return nil if the application’s nib file hasn’t
finished loading,
if the receiver is not active,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
or if the application is hidden.
-----
For a workaround, why not just query for the window that your view is in?
Mike
_______________________________________________
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