PDA

View Full Version : send three variables on button clicked




todizara
Feb 3, 2011, 01:41 PM
Hi!
I want to send three variables when clicking a button, the first is the tag and the other two I do not know how to declerer they.



dejo
Feb 4, 2011, 05:52 PM
I want to send three variables when clicking a button, the first is the tag and the other two I do not know how to declerer they.
You're going to have to be a lot more specific than that. Please elaborate. Also, what do you mean by "send"? And to what? What is the purpose of the three variables and what types are they? Etc. Details like this are important.

todizara
Feb 4, 2011, 08:37 PM
You're going to have to be a lot more specific than that. Please elaborate. Also, what do you mean by "send"? And to what? What is the purpose of the three variables and what types are they? Etc. Details like this are important.

I mean by "send" is when I click on a button I can get these three variable by the action of this button. These variables are all integer.
The first variable is the tag, and the other two will be coordinated (x and y) from the button.

dejo
Feb 4, 2011, 11:44 PM
I mean by "send" is when I click on a button I can get these three variable by the action of this button. These variables are all integer.
The first variable is the tag, and the other two will be coordinated (x and y) from the button.
Well, if your IBAction is constructed in such a way that it accepts an (id)sender parameter, than you can typecast the sender into a UIButton and then just reference its tag property (actually inherited from UIView).

As for getting the x,y coordinates, I'm not sure how you would do that but normally they are determined in reference to the top-left corner, not the bottom.

todizara
Feb 5, 2011, 12:27 AM
Well, if your IBAction is constructed in such a way that it accepts an (id)sender parameter, than you can typecast the sender into a UIButton and then just reference its tag property (actually inherited from UIView).

As for getting the x,y coordinates, I'm not sure how you would do that but normally they are determined in reference to the top-left corner, not the bottom.
I declared the button as

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(40,60, 50, 50);
[myButton setTitle:[NSString stringWithFormat: @"%d",value] forState:UIControlStateNormal];
myButton.tag =6;
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

here x=40, y=50
my problem is now the other two variables.

dejo
Feb 5, 2011, 12:33 AM
I declared the button as

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(40,60, 50, 50);
[myButton setTitle:[NSString stringWithFormat: @"%d",value] forState:UIControlStateNormal];
myButton.tag =6;
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

here x=40, y=50
my problem is now the other two variables.
Don't you mean x = 40, y = 60 ?
And if you just want the x/y coordinates of the origin of the UIButton, those too can be referenced by accessing them through the "property chain" starting with the UIButton's frame.