Why do I have to call showWindow on my NSWindowController twice on 10.5?
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.
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?
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.
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.
精彩评论