NSWindowController:loadWindow从nib加载窗口,但showWindow:什么也不做 [英] NSWindowController: loadWindow loads window from nib but showWindow: does nothing
问题描述
我有一个名为 _PreferencesWindowController
的NSWindowController子类,具有以下实现 -
@synthesize window;
- (id)init {
self = [super initWithWindowNibName:@PreferencesWindow];
if(!self)return nil;
return self;
}
我试图在 _PreferencesWindowController
使用以下代码 -
_preferencesWindowController = [[_PreferencesWindowController alloc] init];
[_preferencesWindowController showWindow:nil];
它什么也不做,我检查了 _preferencesWindowController.window $ c $然而,如果我调用
loadView $>,则调试器会调用
nil
。
< c $ c> on
_preferencesWindowController
窗口可以加载并可见; _preferencesWindowController.window
不再为零值 - [_ preferencesWindowController loadWindow ];
我看过苹果关于NSWindowController的文档,它特别说你不应该直接调用 loadWindow
,而应使用 showWindow:
。
OK我解决了这个问题这是通过查看 NSWindowController
头文件。
问题出在我的头文件_PreferencesWindowController -
@interface _PreferencesWindowController:NSWindowController< NSToolbarDelegate> {
NSWindow * window;
}
@property(assign)IBOutlet NSWindow * window;
@end
通过删除@property声明并更改 NSWindow * window
ivar至 IBOutlet NSWindow * window
, showWindow:
属性声明必须在 showWindow:
方法中导致未定义的行为 NSWindowController
的实现。
I have an NSWindowController subclass called _PreferencesWindowController
with the following implementation -
@synthesize window;
- (id)init {
self = [super initWithWindowNibName:@"PreferencesWindow"];
if (!self) return nil;
return self;
}
And I tried to show the window in _PreferencesWindowController
by using the following code -
_preferencesWindowController = [[_PreferencesWindowController alloc] init];
[_preferencesWindowController showWindow:nil];
It does nothing, and I checked _preferencesWindowController.window
is nil
from the debugger.
However if I call loadView
on _preferencesWindowController
the window can be loaded and is visible; _preferencesWindowController.window
is no longer nil-valued -
[_preferencesWindowController loadWindow];
I looked at Apple's documentation on NSWindowController it specifically says "you should never directly invoke loadWindow
", instead showWindow:
should be used. I'm wondering what I might have missed that resulted in the above-mentioned behaviour I have been seeing.
OK I solved this by looking at the NSWindowController
header file.
The problem is in my header file for _PreferencesWindowController -
@interface _PreferencesWindowController : NSWindowController <NSToolbarDelegate> {
NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
@end
By removing the @property declaration and changing NSWindow *window
ivar to IBOutlet NSWindow *window
, showWindow:
method now works without a glitch.
The property declaration must have resulted in an undefined behaviour in showWindow:
method in NSWindowController
's implementation.
这篇关于NSWindowController:loadWindow从nib加载窗口,但showWindow:什么也不做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!