views:

114

answers:

2

I'm a total newbie to programming in coca 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?

+2  A: 

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 other NSTextField.

Carl Norum
I really wish I understood more of what that meant. I assume that my "controller" is the window, and an "outlet" is sort of like a handle that I can reference in my code, is this right? Would you happen to know of an example?
Daisetsu
Your controller is whatever object you made to be the controller. Have you done any of the Cocoa tutorials? Most cover this sort of stuff in the first 5 pages or so...
Carl Norum
Daisetsu: No, a window (instance of NSWindow or of any subclass thereof) is not a controller. As for your definition of outlet, I suspect you're using the term with a specific meaning from a frame of reference that I don't have, so I can't fairly evaluate your guess's accuracy. To clear up both matters, you should read through the Cocoa Fundamentals Guide: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/
Peter Hosey
+1  A: 

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.

drharris
"...which you then graphically connect to the controls and they update automagically" You seem to be mixing connecting outlets in Interface Builder with Cocoa Bindings. The two are separate.
Joshua Nozzi
Quite possibly... I almost always use a mixture of both. So, it may not be "automagically", but it will be just a single line of code to do it.
drharris