0

我有 8 个 checkbox button(标题为 A、B、C、D、E、F、G、H)和一个 checkbox button(标题为 ' myButton')

当我单击“”复选框时,我想选中所有 8myButton个复选框,如果取消选中 8 个复选框中的任何一个,则取消选中“ myButton”复选框。

让我知道是否有人有答案。

4

2 回答 2

0

给您的复选框标签,例如:1,2,3,...,8 和 9 用于myButton复选框。

当你点击myButton

if(//If my check box button is not already selected)
{
   //check all
   for (int loop = 1; loop<9;loop++)
   {
     UIButton *check = (UIButton *)[self.view viewWithTag:loop];
     //check that button
   }
}
else
{
   //uncheck all
}

要取消选中,myButton您可以使用:

UIButton *check = (UIButton *)[self.view viewWithTag:9];
//uncheck it

编辑:

如果您创建了用于放置按钮的中间视图,请使用该视图而不是self.view.

 UIButton *check = (UIButton *)[placedView viewWithTag:loop];
于 2013-02-05T06:26:06.857 回答
0
 //Creating a button

    for (int i = 100; i < 108; i++) {

        UIButton *checkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        checkBtn.tag = i;
        checkBtn.frame = CGRectMake(15, 10+30*i-100, 250, 30);
        checkBtn.titleLabel.text = [NSString stringWithFormat:@"Btn %d",i];
        [checkBtn setBackgroundImage:[UIImage imageNamed:@"uncheck.png"] forState:UIControlStateNormal];
        [customView addSubview:checkBtn];

    }

全选按钮

-(void) selectAll:(id)sender
{
    for (int i = 100; i < 108; i++) {

        UIButton *selectBtn = (UIButton*)[customView viewWithTag:i];
        [selectBtn setBackgroundImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];

    }
}
于 2013-02-05T06:40:48.980 回答