我具有其中我加載兩種類型的細胞在表視圖從兩個不同的定製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