2015-05-29 66 views
0

我在自定義UITableViewCell中定義了兩個不同的UIButton。該定製UITableViewCell用於UIViewController內的UITableView。現在我想單擊更改UIButton的圖像。我用protocoll和delegate嘗試了它,但它不起作用。任何想法如何我可以做到這一點?單擊自定義UITableViewCell時更改UIButton圖像

+1

你能告訴你已經嘗試的代碼? – Jasper

+0

我已刪除代碼..可能您可以添加一些代碼示例或鏈接。 – Daniela

回答

1

在你cellforowatindexpath方法

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier; 

CellIdentifier = @"Cell"; 
UITableViewCell *cell; 
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 
UIButton *btn = (UIButton *)[cell viewWithTag: 1]; // or however you are initializing the button 

[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; 

return cell; 

} 

-(void)btnClicked:(id)sender 
{ 
    UIButtin *btn = (UIButton *)sender; 
    [btn setImage:[UIImage imageNamed:@"click.png"] forState:UIControlStateNormal]; 
} 
0

當你點擊你的按鈕重新加載該特定的單元格,以及你在哪裏製作自定義單元格時,在委託部分定義委託並更改背景圖片。

願這幫助你。

相關問題