只需在 Cocoa 中制作一个标签说“Hello World”(Mac 编程)
我是 Mac 上可可编程的新手,所以这个问题可能很简单。我有一个窗口,在那个窗口上有一个标签。
我希望能够从我的程序中更新此标签的当前状态或正在发生的事情(例如,读取文件、解析等)。我的问题是我不知道如何访问标签并更改其文本属性。我尝试了“MyWindowName”。希望我能够从窗口引用标签。我什至不知道标签的名称是什么,甚至不知道它是否有名称。
如何在我的程序中引用此标签来更改它?
I'm a total newbie to programming in cocoa for the mac so this question is probably easy. I have a window, and on that window I have a Label.
I want to be able to update this label from my program with the current status or what's going on (eg. reading in file, parsing, etc.). My problem is that I don't know how to access the label and change it's text property. I tried "MyWindowName." hoping I would be able to reference the label from the Window. I don't even know what the labels name is, or even if it has a name.
How do I reference this label in my program to change it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要转到此处并浏览一些教程:http://www.cocoadevcentral.com/
快速总结是,与其他技术不同,您不直接访问控件(或不应访问它们)。相反,您可以在控制器中创建插座,然后以图形方式连接到控件,它们会自动更新。这些教程将为您指明方向。
You probably need to go here and walk through some tutorials: http://www.cocoadevcentral.com/
A quick summary is that unlike other technologies, you don't access the controls directly (or shouldn't access them). Instead, you create outlets in a controller, which you then graphically connect to the controls and they update automagically. These tutorials will show you the way.
标签只是一个
NSTextField
,具有有关编辑/字体等的不同设置。只需在控制器中创建一个连接到 Interface Builder 中视图的插座,然后您就可以像更改任何其他 <代码> NSTextField 。A label is just an
NSTextField
with different settings about editing/fonts, etc. Just make an outlet in your controller that connects to the view in Interface Builder, and you can change it like you would any otherNSTextField
.