我有一个可以工作的UIImageView,但是我想根据某个变量来更改它,所以我有这个:一个名为imagevariable的字符串(它保存image1的值,它是我的项目中的png资源)。所以我有这样的想法:
imageView.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"imagevariable" ofType:@"png"]];但它不起作用。有人能帮帮忙吗?
发布于 2010-10-11 08:54:07
通过将变量名imagevariable括在引号中,它将被视为字符串文字,请尝试以下操作
imageView.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:imagevariable ofType:@"png"]];发布于 2010-10-11 08:53:00
您将图像变量作为字符串传递,这意味着您将按字面意思搜索名为"imagevariable.png“的图像。取而代之的是去掉@"“,让它变成这样:
imageView.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:imagevariable ofType:@"png"]];https://stackoverflow.com/questions/3902882
复制相似问题