如何在单击iphone中的按钮时更改表格单元格内的按钮图像 [英] how to change the button image inside the table cell while clicking the button in iphone

查看:79
本文介绍了如何在单击iphone中的按钮时更改表格单元格内的按钮图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个tableview。我在表格单元格中创建了一个按钮,并为其分配了背景图像。我点击该按钮时想要更改背景图像。我为这个按钮分配了一个动作

I have a tableview in my application. I created a button inside the table cell and assigned a background image to it. I wanted to change the background image when i click that button. I assigned an action for the button like this

-(void)goodBtnClicked:(id)sender {
    [goodBtn setBackgroundImage:[UIImage imageNamed:@"camera.png"] forState:UIControlStateNormal];
}

但是,图像不会被新图像取代。任何人都可以帮我这个吗?

But, the image is not getting replaced with the new image. Can any one help me with this?

推荐答案

浏览所有子视图并找到你的按钮然后改变背景图像

Go through all the subviews and locate your button then change background image

- (void)buttonPressed:(UIButton *)sender{

    UITableViewCell *cell = (UITableViewCell *)sender.superview;
    for (UIView *sub in cell.subviews) {

        if([sub isMemberOfClass:[UIButton class]])
        {
          UIButton * button=[[UIButton alloc] init];
          button=sub;
          [button setImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
        }

    }

}

这篇关于如何在单击iphone中的按钮时更改表格单元格内的按钮图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆