我正在拥有一个UITableview,因为它有三个按钮,并且按钮具有良好的工作条件。我的问题是当我选择任何按钮图像更改为所选图像时。但是当我滚动表格视图时,所选图像会变为普通图像。我想在表格视图中保存所选内容。我看到很多堆栈溢出,但它没有帮助我。任何人都帮帮我。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
CustomizedCellView *cell = (CustomizedCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [table dequeueReusableHeaderFooterViewWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomizedCellView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(80, 27, 36, 36);
[button1 setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"l"ofType:@"png"]] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:@"lblue.png"]
forState:UIControlStateSelected];
[button1 addTarget:self action:@selector(radiobtn4:) forControlEvents:UIControlEventTouchUpInside];
button1.tag=1;
[cell.contentView addSubview:button1];
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(160, 27, 36, 36);
[button2 setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"e"ofType:@"png"]] forState:UIControlStateNormal];
[button2 setImage:[UIImage imageNamed:@"eblue.png"]
forState:UIControlStateSelected];
[button2 addTarget:self action:@selector(radiobtn4:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button2];
button2.tag=3;
button3 = [UIButton buttonWithType:UIButtonTypeCustom];
button3.frame = CGRectMake(240, 27, 36, 36);
[button3 setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"v"ofType:@"png"]] forState:UIControlStateNormal];
[button3 setImage:[UIImage imageNamed:@"vblue.png"]
forState:UIControlStateSelected];
[button3 addTarget:self action:@selector(radiobtn4:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button3];
button3.tag=2;
- (void)radiobtn4:(UIButton *)sender
{
UITableViewCell *cell=(UITableViewCell *)sender.superview;
if(sender.selected == NO)
{
if(sender.tag==1){
UIButton *otherButton=(UIButton *)[cell viewWithTag:1];
otherButton.selected=YES;
UIButton *other=(UIButton *)[cell viewWithTag:2];
other.selected=NO;
}else if(sender.tag==2){
UIButton *otherButton=(UIButton *)[cell viewWithTag:2];
otherButton.selected=YES;
UIButton *other=(UIButton *)[cell viewWithTag:1];
other.selected=NO;
} else if(sender.tag == 3)
{
UIButton *otherButton=(UIButton *)[cell viewWithTag:3];
otherButton.selected=YES;
}
} else if(sender.selected == YES)
{
if(sender.tag==1){
UIButton *otherButton=(UIButton *)[cell viewWithTag:1];
[otherButton setImage:[UIImage imageNamed:@"l.png"]
forState:UIControlStateNormal];
otherButton.selected=NO;
}else if(sender.tag==2){
UIButton *otherButton=(UIButton *)[cell viewWithTag:2];
[otherButton setImage:[UIImage imageNamed:@"v.png"]
forState:UIControlStateNormal];
otherButton.selected=NO;
} else if(sender.tag == 3)
{
UIButton *otherButton=(UIButton *)[cell viewWithTag:3];
[otherButton setImage:[UIImage imageNamed:@"e.png"]
forState:UIControlStateNormal];
otherButton.selected=NO;
}
}
}
以上是我的编码,我想使用任何数组来存储所选图像,我该怎么做,请帮我编码。