文件的所有者认为它是超类

File's owner thinking it is superclass

我的界面生成器发生了一些非常奇怪的事情。所以我在 Xcode 中创建了一个 NSWindowController subclass,并启用了创建 XIB 选项。我开始编码,并成功连接到文件所有者。

但是,当我 运行 我的应用程序时,出现错误:

Failed to connect (workspaceControl) outlet from (NSWindowController) to (NSSegmentedControl): missing setter or instance variable
Failed to connect (workspaceField) outlet from (NSWindowController) to (NSTextField): missing setter or instance variable
Could not connect action, target class NSWindowController does not respond to -changeNumberOfWorkspaces:

我不知道为什么会出现这个错误,因为我的代码设置正确:

并且文件的所有者设置在右边class (AddController):

那么为什么它会尝试将我的视图连接到 NSWindowController 而不是我的子class?

编辑:

我在代码中实际使用 AddController 的地方:

AppDelegate.h

AppDelegate.m

它在 appdelegate 中,因为它是一个菜单栏应用程序。 (以防万一有人想知道)

因为在您的 运行 程序中实例化的实际对象是 NSWindowController,而不是 AddController。您向我们展示了 AddController 已正确声明,并且您向我们展示了您的 nib 的文件所有者设置为 AddController;太好了,这就是为什么您不会收到有关连接不正确的 compile-time 警告或错误的原因。但是您没有向我们展示控制器对象实际实例化的位置;并检查它可能会发现它没有更改为 AddController。所以在运行时你得到了一个 NSWindowController,违反了你向 IB 承诺的情况;所以你会得到运行时错误。