8つbutton
のチェックボックス(タイトルA、B、C、D、E、F、G、H)と1つのチェックボックスbutton
(タイトル' myButton
')があります
''チェックボックスをクリックしたときに8つのチェックボックスをすべて選択したいのですmyButton
が、8つのうちのいずれかが選択解除されている場合は、' myButton
'チェックボックスをオフにします。
誰かが答えを持っているかどうか私に知らせてください。
チェックボックスに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];
//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];
}
}