我具有其中我加载两种类型的细胞在表视图从两个不同的定制classes.I在我的表视图5部分,每个部分具有单一rows.I正在添加一个按钮以我的细胞并在其上点击时的应用程序它将改变button.selected = YES按钮。作为的图像; IKE that.But我的问题是当我滚动单元R的重复,即,如果我在一排然后选择一个按钮,行仅需要的背景图像到change.But在我的情况下,一些小区的按键也changing.Here就是我如何加入things.`更改另一个部分中的按钮图像也更改?
- (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;
[email protected]"skhfkhdf";
[email protected]"dsdbjsbjf";
[email protected]"dshjshhshd";
[cell.lbutton addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside];
cell.myImageView.image=[UIImage imageNamed:@"sdsd.png"];
[email protected]"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;
[email protected]"sdsdsdsd";
[email protected]"sdsdsdsdsd";
[email protected]"sdsasfkdakfhk ";
[cell.likebutton1 addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside];
cell.myImageView1.image=[UIImage imageNamed:@"jpg1.png"];
cell.cellview1.image=[UIImage imageNamed:@"adsdsd.png"];
[email protected]"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;
`但这里的问题是,它也改变also.Can任何其他部分的按钮帮助我吗?
实际上最好只创建一次图像并缓存它,而不是每次创建它,但首先让我们来检查这是否是一个问题;顺便说一句,谢谢编辑sunkehappy –
不客气。而'imageNamed:'将缓存系统的图像。检查这个https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html – sunkehappy