单击自定义UITableViewCell时更改UIButton图像

问题描述:

我在自定义UITableViewCell中定义了两个不同的UIButton。该定制UITableViewCell用于UIViewController内的UITableView。现在我想单击更改UIButton的图像。我用protocoll和delegate尝试了它,但它不起作用。任何想法如何我可以做到这一点?单击自定义UITableViewCell时更改UIButton图像

+1

你能告诉你已经尝试的代码? – Jasper

+0

我已删除代码..可能您可以添加一些代码示例或链接。 – Daniela

在你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]; 
} 

当你点击你的按钮重新加载该特定的单元格,以及你在哪里制作自定义单元格时,在委托部分定义委托并更改背景图片。

愿这帮助你。