UISegmentedControl determine which button is tapped when momentary = YES

40 Views Asked by At

I have a UISegmentedControl element where there are two buttons (i.e "Delete all Points" and "Delete Pt #x"). I don't want the buttons to ever remain selected so I have them set as "momentary = YES". I also don't want to handle click events until AFTER the user has released a button. The problem is, I can't figure out which of the two buttons was pressed within the UISegmentedControl view.

What I've tried:

1) I've tried using the "ValueChanged" event. The nice thing here is I can get the selected index for which button was pressed (even when momentary=YES), but the problem is that this event if triggered when the user presses down... which I don't want. I want the event when the user releases their finger, and at that I only want the event when the user releases WITHIN the button view

2) I've tried using the "Touch Up Inside" event. But it doesn't trigger any events when I tap on one of the buttons...

Any help on this would be appreciated. (Programming in Objective-C)

1

There are 1 best solutions below

0
On

I'm not sure what you mean when you say "I've tried using the "Touch Up Inside" event." Unless you specify precisely what you tried, with code, that is just a meaningless phrase.

Ideally, you'd want create a method something like the following, and set it up as the button's action:

- (IBAction)myButtonTouched:(id)sender forEvent:(UIEvent *)event {
    if (event.type == UIControlEventTouchUpInside) {
        // do your thing
    }
}

Basically you send every user event for that button to the handler and test for the one you want.