如何检测uisegmentedcontrol上的触摸 - 即使在选定的段上?

时间:2012-07-20 07:22:59

标签: iphone ios xcode uisegmentedcontrol

虽然检测到更改与UIControlEventValueChanged一起使用 - 我甚至需要检测所选段的触摸。

我试过

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

但这什么都没有。

有没有办法检测所选细分受众群的触摸?

编辑 - 无需创建新的子类。 ps手势识别器在尝试将其拖动到那里时也不接受segmentcontrol

非常感谢

1 个答案:

答案 0 :(得分:2)

我认为这会起作用

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSInteger oldValue = self.selectedSegmentIndex;
    [super touchesBegan:touches withEvent:event];
    if ( oldValue == self.selectedSegmentIndex )
        [self sendActionsForControlEvents:UIControlEventValueChanged];
}