2

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 = [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]; }
Jean-Luc Godard
  • 1,873
  • 3
  • 28
  • 53

4 Answers4

2

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

cheers :)

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
1

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]; 
}
visakh7
  • 26,380
  • 8
  • 55
  • 69
1

You need to use:

UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort %d.jpg",x]];
Twelve47
  • 3,924
  • 3
  • 22
  • 29
1

Use this

UIImage* photo = [UIImage imageNamed:[NSString stringWithFormat:@"robort %d.jpg",x]];
Chetan Bhalara
  • 10,326
  • 6
  • 32
  • 51