send three variables on button clicked

Discussion in 'iOS Programming' started by todizara, Feb 3, 2011.

  1. macrumors newbie

    Joined:
    Dec 17, 2010
    #1
    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.
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Dec 17, 2010
    #3
    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.
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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.
     
  5. thread starter macrumors newbie

    Joined:
    Dec 17, 2010
    #5
    I declared the button as
    Code:
    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.
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    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.
     

Share This Page