我在表格视图单元格中有三个按钮图像,我想检查它们之间的状况。当我点击按钮1时,意味着按钮3不起作用。单击下一个条件按钮3意味着按钮1不起作用。按钮2可以在所有条件下进行选择。
ButtonImageSelected = [UIImage imageNamed:@"lblue.png"];
ButtonImage = [UIImage imageNamed:@"l.png"];
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(80, 27, 36, 36);
[button1 setBackgroundImage:ButtonImage forState:UIControlStateNormal];
button1.tag = 1;
[button1 setBackgroundImage:ButtonImageSelected forState:UIControlStateSelected];
[cell.contentView addSubview:button1];
ButtonImageSelected1 = [UIImage imageNamed:@"eblue.png"];
ButtonImage1 = [UIImage imageNamed:@"e.png"];
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(160, 27, 36, 36);
button2.tag = 2;
[button2 setBackgroundImage:ButtonImage1 forState:UIControlStateNormal];
[button2 setBackgroundImage:ButtonImageSelected1 forState:UIControlStateSelected];
button2.userInteractionEnabled = YES;
[button2 addTarget:self action:@selector(select_id:)forControlEvents:UIControlEventTouchDown];
[cell.contentView addSubview:button2];
ButtonImageSelected2 = [UIImage imageNamed:@"vblue.png"];
ButtonImage2 = [UIImage imageNamed:@"v.png"];
button3 = [UIButton buttonWithType:UIButtonTypeCustom];
button3.frame = CGRectMake(240, 27, 36, 36);
button3.tag = 3;
[button3 setBackgroundImage:ButtonImage2 forState:UIControlStateNormal];
[button3 setBackgroundImage:ButtonImageSelected2 forState:UIControlStateSelected];
[button3 addTarget:self action:@selector(select_id:)forControlEvents:UIControlEventTouchDown];
[cell.contentView addSubview:button3];
-(void)select_id:(UIButton *) tempBtn {
if (tempBtn.tag == 1) {
[tempBtn setSelected:YES];
[button1 setBackgroundImage:ButtonImageSelected forState:UIControlStateSelected];
[button2 setBackgroundImage:ButtonImageSelected1 forState:UIControlStateSelected];
[button3 setBackgroundImage:ButtonImage2 forState:UIControlStateNormal];
[tempBtn setSelected:! tempBtn.selected];
}
}
答案 0 :(得分:0)
从上面的代码.....
你没有设置按钮1的目标.. 设置button1的目标然后尝试
希望它能起作用......答案 1 :(得分:0)
您需要为所有3个选择器添加一个选择器,您可以为所有三个选择器中使用的所有常用进程添加一个额外的方法。在这些选择器中,您可以放置button.enabled = true;
或button.enabled = false;
例如,这里是按钮1选择器。
-(void)button1Selector: (id)selector {
button3.enabled = false;
[self doOtherStuff];
}