I have a segmented control where the user can select how to order a list. Works fine.
However, I would like that when an already selected segment is tapped, the orde
Big help! What I want to do is have the option of one or no buttons set - and when a button is set, a second tap unsets it. This is my modification:
- (void)setSelectedSegmentIndex:(NSInteger)toValue
{
// Trigger UIControlEventValueChanged even when re-tapping the selected segment.
if (toValue==self.selectedSegmentIndex) {
[super setSelectedSegmentIndex:UISegmentedControlNoSegment]; // notify first
[self sendActionsForControlEvents:UIControlEventValueChanged]; // then unset
} else {
[super setSelectedSegmentIndex:toValue];
}
}
Notify first lets you read the control to find the current setting before it's reset.