在MonoMac中打开Cocoa窗口 [英] Opening a Cocoa window in MonoMac

查看:191
本文介绍了在MonoMac中打开Cocoa窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用MonoMac with monobjc,这是一个非常简单的任务,我打开一个新的窗口,但我似乎完全不能这样做。在Mac上。创建一个新的monobjc项目时,将创建一个MainMenu.xib。我已经设法使用XCode编辑器添加控件和绑定到此文件。此窗口会在应用程序启动时自动打开。



当我尝试创建一个新窗口时,我不能让它显示出来。我通过右键单击MainMenu.xib的父文件夹,然后单击添加文件=>可可窗口模板创建一个.xib文件。这个文件可以在XCode中编辑MainMenu.xib。



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



但我不知道如何打开窗口。我尝试了这个的多个变体:

  var f = new RegularLoginForm(); // which inherit NSWindowController 
f.LoadWindow(); //我试过没有这行
f.ShowWindow(null); //我也尝试在AppDelegate对象(它是MainMenu.xib的控制器)中发送

但没有什么似乎工作 - 也就是说,窗口从来没有打开。任何建议?



编辑:这里是我的.xib和它的配置看起来的截图: https://dl.dropbox.com/u/1545094/so_nswindowcontroller.png

解决方案

您在您的Window.xib中将RegularLoginForm设置为文件的所有者;但是你还连接了文件所有者的窗口出口和Interface Builder中的窗口?



右键单击IB中的文件所有者,然后单击将窗口出口拖动到窗口对象



此外,我尝试了您的代码,调用

  f.ShowWindow(null)

[错误]致命不明原因:System.ArgumentNullException:参数不能为空。
参数名称:sender



如果我指定sender参数,运行正常,例如

  f.ShowWindow(this)

环境只有MonoMac;没有monoobjc(我不知道你为什么或为什么两个一起使用);所以YMMV。


I am trying to accomplish the very simple task of opening a new window, but I seem to be completely unable to do so.

I am using MonoMac with monobjc on a Mac. When creating a new monobjc project, a MainMenu.xib is created. I have managed to add controls and binding to this file using the XCode editor. This window is automatically opened when the application is launched.

When I attempt to create a new window, however, I can't make it show up at all. I created a .xib file by right clicking the parent folder of MainMenu.xib, and clicking Add file => Cocoa Window Template. This file can be edited in XCode just a MainMenu.xib.

I then proceeded to create a class inheriting NSWindowController, and I chose this class as the "File's owner" of the window in my .xib file. I have then been able to design the window, and to add outlets and actions to the controller.

But I can't figure out how to open the window. I have tried multiple variations of this:

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)

But nothing seems to work -- that is, the window never opens. Any suggestions?

EDIT: Here's a screenshot of how my .xib and it's configuration looks: https://dl.dropbox.com/u/1545094/so_nswindowcontroller.png

解决方案

You set RegularLoginForm as File's Owner in your Window.xib; but did you also connect the Window outlet from File's Owner to the Window in Interface Builder?

i.e. Right-click on File's Owner in IB, and click-drag the Window outlet to the Window object

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.

这篇关于在MonoMac中打开Cocoa窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆