Ios5 UISegmentedControl未使用iOS 5启动

Ios5 UISegmentedControl未使用iOS 5启动,ios5,uisegmentedcontrol,Ios5,Uisegmentedcontrol,还有其他人看到这个问题吗?我使用的是分段控件,我已经覆盖了它,因此当用户点击相同的分段(索引)时,它将被取消选择 这在以前的版本中运行良好,但现在在iOS5上进行测试。我发现当您点击同一段时,UIControlEventValueChanged不会发送。因此,当您点击不同的段时,代码可以正常工作,但对于同一段,代码不能正常工作 我的密码 segmentCtrl = [[MySegmentedControl alloc] initWithItems: segmentCtrlLabels]; seg

还有其他人看到这个问题吗?我使用的是分段控件,我已经覆盖了它,因此当用户点击相同的分段(索引)时,它将被取消选择

这在以前的版本中运行良好,但现在在iOS5上进行测试。我发现当您点击同一段时,UIControlEventValueChanged不会发送。因此,当您点击不同的段时,代码可以正常工作,但对于同一段,代码不能正常工作

我的密码

segmentCtrl = [[MySegmentedControl alloc] initWithItems: segmentCtrlLabels];
segmentCtrl.segmentedControlStyle = UISegmentedControlStyleBar;
// Register for touch events
[segmentCtrl addTarget:self action:@selector(segmentedCtrlTouched:) forControlEvents:UIControlEventValueChanged];
我尝试注册UIControlEventTouchUpInside,并获得相同的行为

有什么建议吗

问候,,
Yenyi通过注册触摸事件修复了它。如果触摸的片段相同,我手动发送EventChanged事件

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{    
NSInteger current = self.selectedSegmentIndex;
[super touchesBegan:touches withEvent:event];

if (current == self.selectedSegmentIndex) {
    [self setSelectedSegmentIndex:current];
    [self sendActionsForControlEvents:UIControlEventValueChanged];
}
}

通过注册触摸事件修复了此问题。如果触摸的片段相同,我手动发送EventChanged事件

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{    
NSInteger current = self.selectedSegmentIndex;
[super touchesBegan:touches withEvent:event];

if (current == self.selectedSegmentIndex) {
    [self setSelectedSegmentIndex:current];
    [self sendActionsForControlEvents:UIControlEventValueChanged];
}
}

是的,您需要自己实现控制事件

- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
{
    [super touchesBegan: touches withEvent: event];

    [self sendActionsForControlEvents: UIControlEventTouchDown];
}

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
{
    [super touchesEnded: touches withEvent: event)];

    if (CGRectContainsPoint(self.bounds, [touches.anyObject locationInView: self]))
    {
        [self sendActionsForControlEvents: UIControlEventTouchUpInside];
    }
    else
    {
        [self sendActionsForControlEvents: UIControlEventTouchUpOutside];
    }
}

- (void) touchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event
{
    [super touchesCancelled: touches withEvent: event];

    [self sendActionsForControlEvents: UIControlEventTouchCancel];
}

是的,您需要自己实现控制事件

- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
{
    [super touchesBegan: touches withEvent: event];

    [self sendActionsForControlEvents: UIControlEventTouchDown];
}

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
{
    [super touchesEnded: touches withEvent: event)];

    if (CGRectContainsPoint(self.bounds, [touches.anyObject locationInView: self]))
    {
        [self sendActionsForControlEvents: UIControlEventTouchUpInside];
    }
    else
    {
        [self sendActionsForControlEvents: UIControlEventTouchUpOutside];
    }
}

- (void) touchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event
{
    [super touchesCancelled: touches withEvent: event];

    [self sendActionsForControlEvents: UIControlEventTouchCancel];
}

是的。这里也有类似的问题。iOS API Diff列出了对UISegmentedControl的一些更改,但没有详细说明。我还想知道交易的具体内容。是的。这里也有类似的问题。iOS API Diff列出了对UISegmentedControl的一些更改,但没有详细说明。我还想了解交易的具体内容。+1我在代码中对此做了一些修改,用[self-setSelectedSegmentIndex:UISegmentedControlNoSegment]直接取消选择该段+1我在代码中对此进行了轻微修改,以使用[self-setSelectedSegmentIndex:UISegmentedControlNoSegment]直接取消选择段;