Objective c 为什么一个窗口有两个NSWindowController实例?

Objective c 为什么一个窗口有两个NSWindowController实例?,objective-c,macos,cocoa,interface-builder,Objective C,Macos,Cocoa,Interface Builder,我以编程方式加载窗口,如下所示: OddsWindowController *const controller = [[OddsWindowController alloc] initWithWindowNibName:@"OddsWindow"]; 在NSWindowController的子类OddsWindowController中,我记录了self: - (IBAction)showOdds:(id)sender { NSLog(@"self = %@", self); } -

我以编程方式加载窗口,如下所示:

OddsWindowController *const controller = [[OddsWindowController alloc] initWithWindowNibName:@"OddsWindow"];
在NSWindowController的子类OddsWindowController中,我记录了self:

- (IBAction)showOdds:(id)sender {
    NSLog(@"self = %@", self);
}

- (void)windowDidLoad {
    NSLog(@"self = %@", self);
}

这两个不同的日志语句为self返回不同的值,这意味着我有两个NSWindowController实例。这可能是什么原因造成的?如何停止此操作?

您的OddsWindow.xib中是否还有
OddsWindowController
对象?相反,xib应该通过文件的所有者占位符引用控制器。(文件的所有者将是您的控制器)@MattR这正是问题所在。谢谢