使用 NSWindowController 操作窗口
我有以下代码:
AXWindowController *controller = [[AXWindowController alloc]
initWithWindowNibName:@"ActivateWindow"];
[controller showWindow:nil];
如何使用控制器对窗口 ActivateWindow 进行更改(例如更改窗口上的文本等)?逐步说明将不胜感激。谢谢!
I have the following code:
AXWindowController *controller = [[AXWindowController alloc]
initWithWindowNibName:@"ActivateWindow"];
[controller showWindow:nil];
How do I use controller to make changes to the window ActivateWindow (eg. changing text on the window, etc.)? Step by step instructions would be appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,您的代码片段中没有处理任何实际的窗口元素,您的代码只是初始化并显示窗口。 (我刚刚快速浏览了一下,所以我假设它可以工作)
例如,如果您想在窗口中显示文本,最简单的方法是使用
NSTextField
。非常简单的说明:
现在,要在按下按钮时显示文本,您需要向changeLabel IBAction 添加代码来执行此操作。
例如
[messageLabel setTitleWithMnemonic:@"blah"];
最后,如果你希望它自动显示文本,你不妨在 Interface Builder 中更改标签内容/将代码放在 windowDidLoad 方法中在你的控制器中。
对我来说,这几乎是最简单的方法。不过,我建议您在深入研究更难的东西之前先阅读一些有关 Cocoa 和 Objective-C 的书籍/教程。
Well, none of the actual window elements are handled in your piece of code, your code just initializes and shows the window. (I've just had a quick scan through, so I'm assuming that it works)
If you want to, for example, display text in a window, the simplest way is to use an
NSTextField
.Very simple instructions:
Now, to display text when you press the button, you would add code to the changeLabel IBAction to do so.
e.g.
[messageLabel setTitleWithMnemonic:@"blah"];
And Finally, if you want it to automatically display text, you might as well just change the label content in Interface Builder / place the code in the windowDidLoad method in your controller.
That to me is pretty much the simplest way for you to do it. However, I recommend you read some books / tutorials on Cocoa and Objective-C before delving into harder stuff.
当然,您可以在窗口控制器的代码中以编程方式对窗口进行更改。打开 AXWindowController.m 并执行您想做的任何操作。如果不确切知道您想要做什么(如果您只想创建界面,请使用 Interface Builder)或您的经验水平是什么,则很难给出更明确的答案。
You'd programmatically make changes to your window in the code for your window controller, of course. Open AXWindowController.m and do whatever it is you're wanting to do. It's hard to give a more definite answer without knowing exactly what you're trying to do (if you just want to create the interface, use Interface Builder) or what your experience level is.