1

我正在尝试完成打开一个新窗口的非常简单的任务,但我似乎完全无法这样做。

我在 Mac 上使用 MonoMac 和 monobjc。创建新的 monobjc 项目时,会创建 MainMenu.xib。我已经设法使用 XCode 编辑器向该文件添加控件和绑定。启动应用程序时会自动打开此窗口。

但是,当我尝试创建一个新窗口时,我根本无法让它显示出来。我通过右键单击 MainMenu.xib 的父文件夹并单击 Add file => Cocoa Window Template 创建了一个 .xib 文件。这个文件可以在 XCode 中编辑,只是一个 MainMenu.xib。

然后我继续创建一个继承 NSWindowController 的类,并在我的 .xib 文件中选择这个类作为窗口的“文件所有者”。然后我就能够设计窗口,并向控制器添加出口和操作。

但我不知道如何打开窗户。我尝试了多种变体:

var f = new RegularLoginForm(); //which inherits NSWindowController
f.LoadWindow(); //I have tried without this line
f.ShowWindow(null); // I have also tried sending in the AppDelegate object (which is the controller for MainMenu.xib)

但似乎没有任何效果——也就是说,窗口永远不会打开。有什么建议么?

编辑:这是我的 .xib 及其配置的屏幕截图:https ://dl.dropbox.com/u/1545094/so_nswindowcontroller.png

4

1 回答 1

1

您在 Window.xib 中将 RegularLoginForm 设置为文件的所有者;但是您是否也将 File's Owner 的 Window 插座连接到 Interface Builder 中的 Window?

即在IB中右键单击File's Owner,然后将Window outlet点拖到Window对象上

Further to that, I tried your code and for me it crashes on the call to

f.ShowWindow(null)

[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Argument cannot be null. Parameter name: sender

It runs fine if I assign the sender parameter, e.g.

f.ShowWindow(this)

However, my environment is only MonoMac; no monoobjc (I'm not sure how or why you are using both together?); so YMMV.

于 2013-02-07T16:24:14.013 回答