我有一个应用程序,在该应用程序中,我从两个不同的自定义类在表格视图中加载两种类型的单元格。我的表格视图中有 5 个部分,每个部分都有单行。我在单元格中添加了一个按钮,单击它时会更改按钮的图像.as button.selected=YES;就像那样。但我的问题是当我滚动单元格时重复,即如果我连续选择了一个按钮,那么该行的背景图像只需要更改.但在我的情况下,一些单元格按钮也在改变。这就是我添加东西的方式。
- (UITableVieCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier1 = @"CellIdentifier";
static NSString *CellIdentifier2 = @"Cell";
if (indexPath.section == 0 && indexPath.row==0)
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil)
{
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier1] autorelease];
cell.backgroundView = [ [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"dhjkhs.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.datelabel.text=@"skhfkhdf";
cell.nameLabel.text=@"dsdbjsbjf";
cell.msg.text=@"dshjshhshd";
[cell.lbutton addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside];
cell.myImageView.image=[UIImage imageNamed:@"sdsd.png"];
cell.llabel.text=@"sdjkjskljdls";
cell.llabel.tag=indexPath.section+1;
return cell;
}
else
{
Customcellwithimage *cell = (Customcellwithimage *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil)
{
cell = [[[Customcellwithimage alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier2] autorelease];
cell.backgroundView = [ [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"sdsdsd.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.datelabel1.text=@"sdsdsdsd";
cell.nameLabel1.text=@"sdsdsdsdsd";
cell.msg1.text=@"sdsasfkdakfhk ";
[cell.likebutton1 addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside];
cell.myImageView1.image=[UIImage imageNamed:@"jpg1.png"];
cell.cellview1.image=[UIImage imageNamed:@"adsdsd.png"];
cell.llabel1.text=@"sdsdsdsdl";
cell.llabel1.tag=indexPath.section+2;
cell.bannerview1.image=[UIImage imageNamed:@"dsdsd.png"];
return cell;
}
return Nil;
}
i have 10 sections each returning 1 row.My problem is i need to change the image of the button when clicked.I was adding that button in the customcellwith image class as
[lbutton1 setImage:[UIImage imageNamed:@"sdsd.png"] forState:UIControlStateNormal];
[lbutton1 setImage:[UIImage imageNamed:@"sdsdsd.png"] forState:UIControlStateSelected];
lbutton1.selected=NO;`
在我的代码中我添加了`
UIButton *button = (UIButton *)sender;
button.selected=YES;
` 但这里的问题是它也改变了另一个部分的按钮。有人可以帮我吗?