xcode从字符串中设置图像名称

时间:2011-10-16 18:28:07

标签: xcode

我正在从视图控制器发送图像名称。在接收视图控制器中,我想将UIImageview中的图像设置为字符串加.png

我正在尝试的代码(不起作用)是:

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        NSString *imagefile;
        imagefile=[NSString stringWithFormat:@"%d.png",myColour];
        myImage.image=[UIImage imageNamed:imagefile];
        [output setText:myString];
//      [imagefile release];
    }

在这里的代码中,myColour是从上一页传递的字符串 - 所以我有一些名为yellow.png,blue.png等的图像

感谢。

1 个答案:

答案 0 :(得分:0)

您想要的代码是:

imagefile = [NSString stringWithFormat:@"%@.png", myColour];

使用%@打印对象的值(NSObject子类,如NSString)。