tags:

views:

22

answers:

1

In Interface Builder I made a checkbox and a textbox. When the user checks the checkbox I want a message to appear in the textobx that says "the checkbox is checked." If the box is unchecked I want a message to appear in the textbox that says "the check box is unchecked." The problem is that I don't know how to get the status of the checkbox.

+2  A: 

Ask the button for its state. If it's NSOnState, it's checked. If it's NSOffState, it's not checked.

Chuck
What's the method to get the state?
Phenom
Phenom: He already answered that in the answer. If you still don't know, check the documentation. http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSButton_Class/
Peter Hosey
Do I have to assign an IBOutlet to the button? An IBAction is already assigned to it. That's where I set the text in the textbox.
Phenom
Phenom: You have your first sentence the wrong way around. An IBOutlet is a variable (or a property), so you assign the button to the outlet. You do that in IB so that your code can know about the button through the outlet. As for your third sentence, the button's target and action are unrelated to outlets; an outlet is how another object knows about the button, whereas the button's target is how it knows what other object to send its action to.
Peter Hosey
@Phenom: You don't really need to assign the button to an outlet if all you want to do is update a text field when it's clicked. In the button target's action method, the button will be the argument (traditionally called `sender`). So that method can just use the sender argument to talk to the button, and since the button isn't needed anywhere else, you don't need to create any IBOutlets.
Chuck