如何获取在xib文件中创建的NSWindow的引用? [英] How can get a reference to an NSWindow created in a xib file?
问题描述
我使用xib文件显示名为mainWindow的 NSWindow
- 现在我想通过代码获取对mainWindow的引用(例如 NSWindow * mainWindow
)。我在文档中找不到任何内容,任何指针?
I use a xib file to show an NSWindow
named mainWindow - now I want to get a reference to mainWindow via code (e.g. NSWindow *mainWindow
). I can't find anything in the documentation, any pointers?
推荐答案
xib文件中会有app占位符对象委托和/或文件的所有者。
The xib file will have placeholder objects in it for the app delegate and / or the file's owner.
假设其中包含app委托,您可以获取对窗口或xib中任何对象的引用
On the assumption that it has the app delegate in it, you can get a reference to the window or any object in the xib by
-
在正确类型的app委托中声明属性,并将IBOutlet作为其类型的一部分:
Declare a property in the app delegate of the right type and with IBOutlet as part of its type:
@property (weak) IBOutlet NSWindow* theWindow;
在xib中找到app delegate对象。按住控制键时单击并拖动它。你应该在鼠标指针和对象之间找到一条线。
Locate the app delegate object in the xib. Click and drag it while the control key is pressed. You should get a line between the mouse pointer and the object.
这篇关于如何获取在xib文件中创建的NSWindow的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!