在iphone中的imageView中设置图像时出错

时间:2011-04-12 09:00:35

标签: iphone ios uiimageview

我已经编写了一个用于设置imageview的代码...按照单击的按钮...但我的问题是当我按下按钮时它给我的错误就像...函数ImageNamed的参数太多了...在执行此行时......

UIImage* photo = [UIImage imageNamed:@"robort %d.jpg",x];

整个代码是......

-(void)buttonClicked:(UIButton*)button
{
NSLog(@"%d",button.tag);
int x;
x=button.tag;
// Create the image view.
UIImage* photo = [UIImage imageNamed:@"robort %d.jpg",x];
NSLog(@"%d",x);
CGSize photoSize = [photo size];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, photoSize.width, photoSize.height)];
[imageView setImage:photo];
[self.view addSubview:imageView]; }

4 个答案:

答案 0 :(得分:2)

使用UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort de nero%d.jpg",x]];

欢呼:)

答案 1 :(得分:1)

试试这个

-(void)buttonClicked:(UIButton*)button
{
NSLog(@"%d",button.tag);
int x;
x=button.tag;
// Create the image view.
NSString *imageName = [NSString stringWithFormat:@"robort %d.jpg",x];
UIImage* photo = [UIImage imageNamed:imageName];
NSLog(@"%d",x);
CGSize photoSize = [photo size];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, photoSize.width, photoSize.height)];
[imageView setImage:photo];
[self.view addSubview:imageView]; 
}

答案 2 :(得分:1)

您需要使用:

UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort %d.jpg",x]];

答案 3 :(得分:1)

使用此

UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort %d.jpg",x]];