【问题标题】:automatically unselect previous selected button in UItableview in iphone在 iphone 的 UItableview 中自动取消选择上一个选择的按钮
【发布时间】:2012-10-07 15:46:24
【问题描述】:

我有一个带有多个自定义按钮的表格视图。当我选择一个按钮时,该按钮应突出显示,如果我选择任何其他按钮,则前一个选择的按钮应自动取消突出显示,从而突出显示当前选择的按钮。我该怎么做……?

-(IBAction)buttonPressed:(UIButton *)sender {

 tempBtn.selected = NO;
    if (tempBtn != sender){
       tempBtn = sender;
        tempBtn.selected =YES;
       [ tempBtn setBackgroundColor:[UIColor redColor]];
    }
    else{
        tempBtn = nil;
    }
}

我正在这样做,但是在这里我单击的所有按钮都更改为红色,而不是删除以前的选择颜色(红色)..我该怎么做?

【问题讨论】:

    标签: xcode uitableview uibutton


    【解决方案1】:

    你是说如果它已经是红色的,它会变红,但如果按钮已经是红色,你希望它变成另一种颜色/清除?好像您在选择多行?

    tempBtn.selected = !tempBtn.selected;
    if(tempBtn.selected)
    {
       tempBtn.backgroundcolor = [UIColor redColor];
    }
    else
    {
       tempBtn.backgroundcolor = [UIColor clearColor];
    }
    

    编辑:由于轻微的问题更改

    按下按钮:

    -(void)buttonPress:(id)sender
    {
      //Change Color to Red
       if([myMutableArray count] > 0
        {
          UIButton* button = (UIButton *)[self.view viewWithTag:[myMutableArray objectAtIndex:0];
           button.setBackgroundColor = [UIColor clearColor];
           [myMutableArray removeAllObjects];
        }
        [myMutableArray addObject:[sender tag]];
    }
    

    【讨论】:

    • 不,我的意思是我在 gridview 中有很多按钮。当我在其中选择一个按钮时应该是红色的,如果我选择另一个按钮,那么之前选择的按钮应该是清晰的颜色并呈现选择的按钮应该是红色的。我不知道如何获得它...
    猜你喜欢
    • 2018-07-15
    • 2019-03-25
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    • 2011-11-05
    相关资源
    最近更新 更多