Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Button Tag Value in iPhone

Tags:

ios

uibutton

I have made 20 Buttons dynamically, and I got the tag values of all Buttons.

But I need to know how to use that tag values.

I need information on every button pressed with tag values.
So, how do I use those tag values?

like image 240
Sanjay Avatar asked Dec 01 '22 07:12

Sanjay


1 Answers

You need to set target-action of each button.

[button setTarget:self action:@selector(someMethod:) forControlEvents:UIControlEventTouchUpInside];

Then implement someMethod: like this:

- (void)someMethod:(UIButton *)sender {
    if (sender.tag == 1) {
        // do action for button with tag 1
    } else if (sender.tag == 2) {
        // do action for button with tag 2
    } // ... and so on
}
like image 53
Filip Radelic Avatar answered Dec 09 '22 17:12

Filip Radelic