0

我正在为 iOS 开发一个应用程序(仍在学习),并且我有一个类似于组合框的按钮:单击它会打开一个带有表格视图的新场景,显示单击时返回到前一个场景的元素和调用updatePartner:方法。到目前为止,它工作得很好。但是当我尝试更新按钮的图像时,它并没有更新它......

- (void) updatePartner:(NSInteger)index
{
NSLog(@"updatePartner: %i", index);

NSString *partnerImage = @"";
UIImage *image = @"";
NSString *text = @"";

switch (index)
{
    case 0:
        partnerImage = @"ic_pcmedic_h45.png";
        image = [UIImage imageNamed:partnerImage];
        break;

    case 1:
        partnerImage = @"ic_sapo_h45.png";
        image = [UIImage imageNamed:partnerImage];
        break;

    case 2:
        partnerImage = @"ic_telepac_h45.png";
        image = [UIImage imageNamed:partnerImage];
        break;

    case 3:
        partnerImage = @"ic_meo_h45.png";
        image = [UIImage imageNamed:partnerImage];
        break;

    case 4:
        partnerImage = @"ic_zon_h45.png";
        image = [UIImage imageNamed:partnerImage];
        break;

    case 5:
        partnerImage = @"ic_caboviaso_h45.png";
        image = [UIImage imageNamed:partnerImage];
        break;

    case 6:
        partnerImage = @"ic_artelecom_h45.png";
        image = [UIImage imageNamed:partnerImage];
        break;

    case 7:
        text = @"Ainda não sou cliente";
        break;

    default:
        break;
}

if (index <= 6)
    [[self partnerButton] setImage:image forState:UIControlStateNormal];
else
    [[self partnerButton] setTitle:text forState:UIControlStateNormal];

[[self partnerButton] setNeedsDisplay];
[[self view] setNeedsDisplay];
}

任何帮助将不胜感激!

更新:我一直在用这个,但仍然没有弄清楚....它不起作用......请帮助!谢谢!

问候,里卡多·阿门多埃拉

4

2 回答 2

0

你可以试试这个...

if (index <= 6) {
    [[self partnerButton] setBackgroundImage:image forState:UIControlStateNormal];
} else {
    [[self partnerButton] setTitle:text forState:UIControlStateNormal];
}
于 2012-10-03T01:16:36.720 回答
0

你为 .h 文件中的图像制作了 IBOutlets 吗?

然后你可以这样做:

yourimagesetoutlet.image = [UIImage imageNamed: @"imagename.png"];

试试用这个!!这可能会解决你的问题

做类似的东西

switch (index)
{
    case 0:
        yourimagesetoutlet.image = [UIImage imageNamed: @"imagename.png"];

        break;
}
于 2012-10-03T00:12:55.640 回答