Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton touchUpInside action firing multiple times per click

I have three buttons set up in Interface Builder, each tied via touchUpInside to btnSelection:

- (IBAction)btnSelection:(id)sender {
    NSLog(@"tag: %i", [sender tag]);
}

In my console, the first click registers correctly (after a second or so delay, which seems a bit weird) but any subsequent touch of any of the 3 buttons results in first logging the previous tag value, then logging the new tag.

Touch #1 (btn w/ tag=0):

tag:0

Touch #2 (btn w/ tag=1):

tag:0 tag:1

Touch #3 (btn w/ tag=2):

tag:1 tag:2

and so on.

I can't figure out why two events are being logged each time (with the first being the previously touched button.

like image 759
Will Henderson Avatar asked Feb 02 '26 13:02

Will Henderson


1 Answers

One possible reason is that if you hooked up your button to the event, and then copied that button and hooked up the event again, you might be calling your btnSelection function twice.

In interface builder, check to see that you only have one callback to btnSelection

like image 56
Benny Wong Avatar answered Feb 04 '26 07:02

Benny Wong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!