我有一个nswindowController子类称为 _PreferencesWindowController 具有以下实施 -

@synthesize window;

- (id)init {

 self = [super initWithWindowNibName:@"PreferencesWindow"];
 if (!self) return nil;

 return self;
}

我试图展示窗口 _PreferencesWindowController 通过使用以下代码 -

_preferencesWindowController = [[_PreferencesWindowController alloc] init];
[_preferencesWindowController showWindow:nil];

它什么都不做,我检查了 _preferencesWindowController.windownil 来自调试器。

但是,如果我打电话 loadView_preferencesWindowController 可以加载窗口并且可见; _preferencesWindowController.window 不再是尼尔值 -

[_preferencesWindowController loadWindow];

我查看了Apple在NswindowController上的文档,它专门说:“您永远不要直接调用 loadWindow“, 反而 showWindow: 应该使用。我想知道我可能错过了什么导致了我所看到的上述行为。

有帮助吗?

解决方案

好吧,我通过看着 NSWindowController 标题文件。

问题在于我的标题文件_preferencesWindowController-

@interface _PreferencesWindowController : NSWindowController <NSToolbarDelegate> {

    NSWindow *window;

}

@property (assign) IBOutlet NSWindow *window;

@end

通过删除@property声明和更改 NSWindow *window 伊瓦到 IBOutlet NSWindow *window, showWindow: 方法现在没有小故障工作。

财产声明必须导致不确定的行为 showWindow: 方法IN NSWindowController实施。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top