views:

30

answers:

1

Ok, i'm new to the whole GUI programming so this might be a very simple question but has proven difficult to me.

I have an application with 3 buttons. Button A is the main button, it starts and stops the application. I created a class with an IBAction on it and wrote the code for that button. it works. I also have button B and C that are used to set options. I created two IBOutlets: ButtonBAction and ButtonCAction, and control dragged (in interface builder) my class to each button and selected the action.

Now, the idea is that when button B is pressed an option is set, basically an int is set (on the class for button A) to 1. The same with button C. How do I do this? How do I detect that button B or C were clicked and set those ints?

Thanks

+2  A: 

You can create another IBAction of setOptionWithButton:, both buttons can call this method. Then set the option based on which button was used. You can set an identification value for each button in Interface Builder to make this detection easier.

MarkPowell
OK, so I need to remove the connection to the IBOutlet, right? And, how to I access that identification value?
Uri
For what you describe, you do not need the IBOutlet connection. The button is sent as the "sender" to the IBAction.
MarkPowell
thanks, so: it's sender.id? sender:id? sender->id? I still to grasp some of the objective C notations...
Uri
- (IBAction)setOption:(id)sender
MarkPowell
Thanks, I already created the IBAction, what I am asking is I set Button B's object ID to a number, how do I know now within the IBAction that that button was pressed? How do I test sender for that ID?
Uri
You can set the id tag in Interface Builder under View Attributes. It's a property of the button object, so you can access it via .tag dot notation.
MarkPowell
Sorry to nag. But I am all confused now. I have the button, it has a tag = 1, then under the Button identity I set an objectId. I can't find any other ID. Then I went to my newly created IBAction and wrote:if (sender.tag == 1){}
Uri
and I other different ways, they all get errors. would you be so kind as to write a line of code to access the ID you are telling me? it clear that sender.tag doesn't work
Uri
Ok, I got it. Thanks for the help!
Uri