开发者

error while setting image in imageView in iphone

I have written a code for setting imageview ...as per the button clicked...but my problem is when i press the button it is giving me the error like...too many arguments to function ImageNamed...while executing this line...

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

the whole code is....

-(void)buttonClicked:(UIButton*)button
{
NSLog(@"%d",button.tag);
int x;
x=button.tag;
// Create the image view.
UIImage* photo = [U开发者_运维百科IImage 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]; }


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

cheers :)


Try this

-(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]; 
}


You need to use:

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


Use this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜