2

我有一个UIButton内部自定义单元格。选择单元格后,按钮也会将其状态更改为“突出显示”

我想阻止这种行为。该按钮仅在被特别触摸时才应更改其状态(我在我的 中处理IBAction)。

可能吗?

4

3 回答 3

3

您可以子类UIButton化并覆盖该setSelected:方法,而不是调用[super setSelected:]或调用它[super setSelected:NO];

如果您想自己选择它,请致电[super setSelected:YES];

于 2012-12-28T14:21:22.180 回答
1

这是我最终使用的(在我的自定义单元实现中):

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    BOOL highlightState = self.btn.highlighted;
    BOOL selectedState = self.btn.selected;

    [super setSelected:selected animated:animated];

    self.btn.selected = selectedState;
    self.btn.highlighted = highlightState;
}

- (void) setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    BOOL highlightState = self.btn.highlighted;
    BOOL selectedState = self.btn.selected;

    [super setHighlighted:highlighted animated:animated];

    self.btn.selected = selectedState;
    self.btn.highlighted = highlightState;
}
于 2012-12-30T14:11:34.223 回答
0

在您的单元格的类覆盖中:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
  [super touchesBegan:touches withEvent:event];
  self.button.highlighted = NO;
}
于 2012-12-29T09:27:17.757 回答