Frameworks & XIB
I'm facing a strange problem concerning a XIB file in my framework. This XIB file contains a NSWindow
, NSTableView
and two buttons, all of which are connected via Outlets. The TableView and Buttons work as expected, but the NSWindow
is always (null)
.
The window's outlet is connected and the XIB is being loaded correctly, so I'm really surprised that this doesn't work for this particular instance.
I load the XIB like this: BOOL success = [NSBundle loadNibNamed:@"SomeXIB" owner:self];
Then I try to modify the window:
[window setLevel:NSModalPanelWindowLevel];
[window center];
[window makeKeyAndOrderFront:self];
NSLog(@"Window: %@",window);
The NSLog
statement always returns (null)
and none of the methods above do anything, the window only shows up because Visible At Launch
is checked and won't otherwise. (which proves that the XIB is loaded fine)
Am I missing something?
Edit:
Here's all I do to the window:
BOOL success = [NSBundle loadNibNamed:@"BrowserPrompt" owner:self];
if (success == NO)
{
NSLog(@"Couldn't load XIB.");
return NO;
}
[[self delegate] pickerWillShow:self];
[window setLevel:NSModalPan开发者_StackOverflow社区elWindowLevel];
[window center];
[window makeKeyAndOrderFront:self];
Almost certainly, one of the following is true:
self.window
is not an IBOutlet- Your XIB's File Owner is not of the same class as
self
- You have not connected the NSWindow in IB to the File Owner's
window
IBOutlet. - You are setting
window
tonil
between the load and the usage. - You are running the window modifying code before the load code (this mistake is surprisingly common).
Override setWindow:
so you can put in logging or a breakpoint, and make sure it's being called, and check whether it's being called with nil
or a proper value.
精彩评论