views:

709

answers:

1

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.

+1  A: 

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

Benny Wong
Thanks for the reply. I definitely only have one callback to btnSelection for each button. The buttons are distinct, and were created individually, so they shouldn't (and by all accounts don't) have any left over callbacks from being duplicated from each other.
Will Henderson