views:

89

answers:

1

This is probably a really simple question but I can't seem to find anything in the APIs or across any search engine.

I have a Segmented control that i have set to momentary as a user will select a couple of makes of a car that they want to search for. The issue that I'm running into is that I can't seem to figure out how to recognize which segment was selected. In regular mode its a simple SelectedSegment = index but with momentary its my understanding that the selected segment is always -1 as none are ever "selected"

I have a handler for ValueChanged but I can't figure out what I'm checking for or what I should be sending to determine which segment was selected. Any help would be greatly appreciated. I'm using monotouch but Obj-C would be fine as well.

Thanks!

+2  A: 

In your handler, you should check the selectedSegmentIndex to determine which segment was selected:

- (void) valueChanged:(UISegmentedControl *) control {
   switch(control.selectedSegmentIndex) {
      case 0:
         //yata yata yata
         break;
   }
}
Jacob Relkin
This is correct. The UISegmentedControl only tracks the *last* item that was selected, not *all* currently selected items. You'll have to maintain the currently selected list in your own object.
John Franklin
Awesome, Thanks for the help!
Adam