Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Support for reselecting segmented control. segmentedControl.momentary = YES;
#import "SDSegmentedControlHelper.h"
@implementation SDSegmentedControlHelper
+(void)selectTrafficSegmentInSegmentedControl:( UISegmentedControl* )sender
{
NSArray* segments = [ sender subviews ];
id trafficSegment = segments[1];
id campaignSegment = segments[0];
[ trafficSegment setSelected: YES ];
[ campaignSegment setSelected: NO ];
}
+(void)selectCampaignSegmentInSegmentedControl:( UISegmentedControl* )sender
{
NSArray* segments = [ sender subviews ];
id trafficSegment = segments[1];
id campaignSegment = segments[0];
[ trafficSegment setSelected: NO ];
[ campaignSegment setSelected: YES ];
}
+(NSInteger)trafficSegmentIndex
{
return 0;
}
+(NSInteger)campaignSegmentIndex
{
return 1;
}
+(NSUInteger)unsignedTrafficSegmentIndex
{
return 0;
}
+(NSUInteger)unsignedCampaignSegmentIndex
{
return 1;
}
@end
-(IBAction)navigationSegmentTouched:( UISegmentedControl* )sender
{
NSInteger selectedIndex = sender.selectedSegmentIndex;
[ sender setSelectedSegmentIndex: UISegmentedControlNoSegment ];
if ( [ SDSegmentedControlHelper trafficSegmentIndex ] == selectedIndex )
{
[ SDSegmentedControlHelper selectTrafficSegmentInSegmentedControl: sender ];
}
else
{
[ SDSegmentedControlHelper selectCampaignSegmentInSegmentedControl: sender ];
}
/// Code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment