Why do I have to call showWindow on my NSWindowController twice on 10.5?
Asked Answered
P

3

3

I've got a subclass of an NSWindowController that I'm using to load a window from a nib and show it on the screen. Below is the code that is called when I want to show the window. On 10.6 when showCustomWindow is called the window is displayed, but on 10.5 this method has to be called twice to get the window to display.

-(IBAction)showCustomWindow:(id)sender 
{
   if(!windowController){
       windowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindow"];
    }

    [windowController showWindow:self];
}

The window has "Visible at Launch" checked and unchecking it didn't seem to make a difference.

Edit: I realized that the problem I was having was not related to my NSWindowController or showWindow. I had that set up correctly. I did however find out that not all classes implement awakeFromNib. In one of my NSView subclasses (that was in the nib I was trying to load), i was calling [super awakeFromNib] which was giving me a "does not respond to selector" (but only on 10.5 which is strange). So, I could have just taken out [super awakeFromNib] but I opted for the hopefully more robust:

if([NSView instancesRespondToSelector:@selector(awakeFromNib)]) {
    [super awakeFromNib];
}

That allowed my nib to load normally and showWindow to work properly.

Professor answered 7/10, 2009 at 2:49 Comment(1)
The docs read as follows: "You should call the super implementation of awakeFromNib only if you know for certain that your superclass provides an implementation. Because the Application Kit does not provide a default implementation of the awakeFromNib method, calling super results in an exception if the parent class does not implement it. Classes whose immediate parent class is NSObject or NSView do not need to call the super implementation." In other words, don't bother calling it on super if it's just an NSView subclass.Trying
S
4

Visible at Launch should be unchecked if you want to use -showWindow: to control the timing of that window's visibility.

Everything else seems right from what you've shown us so this is just a guess but did you forget to connect the window outlet on your File's Owner object to the window in your nib?

Supple answered 7/10, 2009 at 18:12 Comment(0)
V
0

Are you calling -showWindow before the window has finished loading from its nib? You might want set a breakpoint in [MyWindowController awakeFromNib] to find out.

Veldaveleda answered 7/10, 2009 at 6:51 Comment(0)
C
0

Edit: OK Sorry I misunderstood your question and see that you need to call showWindow twice. I don't have an answer for that.

The behaviour you're seeing is correct since the method initWithWindowNibName: won't actually load the nib. Nib loading happens lazily .. so after you invoke the showWindow method, or some other method such as window that requires the nib to load.

Clerestory answered 7/10, 2009 at 7:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.