Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect touches on uisegmentedcontrol - even on selected segment?

While detecting changes works with UIControlEventValueChanged - I need to detect touches even on selected segments.

I tried

   [onOffSC addTarget:self
            action:@selector(segmentedControlPushed)
  forControlEvents:UIControlEventAllTouchEvents];

But this fires nothing.

Is there a way to detect touches on a selected segment?

EDIT - without having to create a new subclass. ps also the gesture recognizer does not accept the segmentcontrol when trying to drag it there

Many thanks

like image 248
user387184 Avatar asked Jul 20 '12 07:07

user387184


1 Answers

I think this will work

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSInteger oldValue = self.selectedSegmentIndex;
    [super touchesBegan:touches withEvent:event];
    if ( oldValue == self.selectedSegmentIndex )
        [self sendActionsForControlEvents:UIControlEventValueChanged];
}
like image 140
Sebastian Łuczak Avatar answered Nov 11 '22 12:11

Sebastian Łuczak