My aim is to trigger UIControlEventValueChanged delegate again when i tapped an already selected segment .
So i have referred the below links
uisegmentedcontrol-register-taps-on-selected-segment
maintaining-selection-in-uisegmentedcontrol
As per the links i have created a uisegmentedcontrol subclass , implemented the - (void) setSelectedSegmentIndex:(NSInteger)toValue {
method and wrote the codes (from the above links).
Its worked fine with Ipad1. However the setSelectedSegmentIndex in the inherited/sub class is not triggering in Ipad2 when tapped an already selected segment!!!! however it is working fine when i tapped an unselected segment index.
The code i done is below
Main Class
ReselectableSegmentControl *firstNextSegmentedControl = [[ReselectableSegmentControl alloc] init];
firstNextSegmentedControl.frame = CGRectMake(xCordinate, 255, 188, 50);
firstNextSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
firstNextSegmentedControl.tag = index + 1;
[firstNextSegmentedControl addTarget:self action:@selector(firstNextThenSegmentedControlValueChanged:) forControlEvents:UIControlEventValueChanged];
[firstNextSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"NoTimerCounter.png"] atIndex:0 animated:YES];
[firstNextSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"Timer.png"] atIndex:1 animated:YES];
[firstNextSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"Counter.png"] atIndex:2 animated:YES];
firstNextSegmentedControl.selectedSegmentIndex = 0;
[self.view addSubview:firstNextSegmentedControl];
[firstNextSegmentedControl release];
firstNextSegmentedControl = nil;
UISegmentSubClass .h file
#import <Foundation/Foundation.h>
@interface ReselectableSegmentControl : UISegmentedControl {
}
@end
UISegmentSubClass .m file
-(void)setSelectedSegmentIndex:(NSInteger )selectedValue{
if (selectedValue==self.selectedSegmentIndex) {
[self sendActionsForControlEvents:UIControlEventValueChanged];
}
[super setSelectedSegmentIndex:selectedValue];
}
or
-(void)setSelectedSegmentIndex:(NSInteger )selectedValue{
if (self.selectedSegmentIndex == selectedValue) {
//doing my operation if tapped again the selected value.
else {
super.selectedSegmentIndex = selectedValue;
}
}
or
- (void) setSelectedSegmentIndex:(NSInteger)toValue {
if (self.selectedSegmentIndex == toValue) {
[super setSelectedSegmentIndex:UISegmentedControlNoSegment];
} else {
[super setSelectedSegmentIndex:toValue];
}
}
The all above methods are not working with Ipad2.
Any help on this issue is appreciated.
Thanks.