some_id
some_id

Reputation: 29906

Loading an Array Image item using the formatted NSString

I want to load an image from an array and set the view to display this image.

The current code isnt loading anything, just a gray image full screen.

myView.image = [UIImage imageNamed:[names objectAtIndex:r]]

If I have a counter r, which I use to access the index. How could it be done to load an image as such

myView.image = [UIImage imageNamed:@"3.png"];

but using r as the placeholder for the number, in this case 3.

If I have images 1.png to e.g. 10.png and want to use the r which I already increment and decrement, ow could I call the correct image using a formatted string in the place of

@"3.png" ?

Thanks in Advance.

Upvotes: 1

Views: 189

Answers (1)

pgb
pgb

Reputation: 25011

You can do:

myView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", r]];

Upvotes: 2

Related Questions