问题描述
我在表格视图中有三个按钮图像,我想检查它们之间的条件.当我单击按钮1时,表示背景图像变为蓝色.同时单击按钮1,它将变为正常状态的白色.同样,另外两个按钮.
I am having three button image in table view, I want to check the conditions between them. when I click the button 1 means background image change to blue colour. at the same time I click the button 1 it will move to normal state white colour. Same for another two buttons.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath![button3 condition][3]
{
static NSString *cellIdentifier = @"HistoryCell";
CustomizedCellView *cell = (CustomizedCellView *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[CustomizedCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UIButton *button1;
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(80, 27, 36, 36);
[button1 setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"l"ofType:@"png"]] forState:UIControlStateNormal];
button1.tag = 1;
[button1 addTarget:self action:@selector(radiobtn:) forControlEvents:UIControlEventTouchUpInside];
[button1 setSelected:true];
[cell.contentView addSubview:button1];
UIButton *button2;
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(160, 27, 36, 36);
[button2 setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"e"ofType:@"png"]] forState:UIControlStateNormal];
button2.tag = 1;
[button2 addTarget:self action:@selector(radiobtn:) forControlEvents:UIControlEventTouchUpInside];
[button2 setSelected:true];
[cell.contentView addSubview:button2];
UIButton *button3;
button3 = [UIButton buttonWithType:UIButtonTypeCustom];
button3.frame = CGRectMake(240, 27, 36, 36);
[button3 setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"v"ofType:@"png"]] forState:UIControlStateNormal];
button3.tag = 1;
[button3 addTarget:self action:@selector(radiobtn:) forControlEvents:UIControlEventTouchUpInside];
[button3 setSelected:true];
[cell.contentView addSubview:button3];
return cell;
}
我的条件是:单击按钮1时,按钮3不应更改.当单击按钮3时,意味着按钮1不应更改.按钮2可以在两种情况下都可以选择.
My condition is: when button 1 is clicked means button 3 should not change. when button 3 is clicked means button 1 should not change.button 2 can select in both the condition.
- (void)radiobtn:(UIButton *)button
{
if(button.tag == 1)
{
[button setImage:[UIImage imageNamed:@"lblue.png"] forState:UIControlStateSelected];
}
if(button.tag == 2)
{
[button setImage:[UIImage imageNamed:@"eblue.png"] forState:UIControlStateSelected];
}
if(button.tag == 3)
{
[button setImage:[UIImage imageNamed:@"vblue.png"] forState:UIControlStateSelected];
}
}
任何人都可以帮助我进行编码.
can any one help me in coding.
推荐答案
首先,您可以为每个按钮的样式设置不同的标签
First of all you can set different tag for each button's like
button.tag == 1,
button.tag == 2,
button.tag == 3
然后您可以像这样编写 radiobtn
操作..
And then after you can write your radiobtn
Action like this way..
-(IBAction) radiobtn:(id)sender
{
UIButton *yourBtn = (UIButton *)[self.view viewWithTag:[sender tag]];
if(yourBtn.tag == 1) {
[yourBtn setImage:[UIImage imageNamed:@"lblue.png"] forState:UIControlStateSelected];
}
else if(yourBtn.tag == 2){
[yourBtn setImage:[UIImage imageNamed:@"eblue.png"] forState:UIControlStateSelected];
}
else{
[yourBtn setImage:[UIImage imageNamed:@"vblue.png"] forState:UIControlStateSelected];
}
}
这篇关于如何在UITableview中检查UIButtons的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!