views:

59

answers:

2

Hi, I'm still very new to cocoa touch so please excuse any terminology that I may have got wrong.

I have a bunch of images in my bundle consecutively named image0.png, image1.png etc...

I have a picker in a viewcontroller and an instance variable that keeps track of the current row.

When a user clicks a button I want to be able to create a uiImageView object (and first test whether the view already exists) based on the row number, ie: uiImageView *imageView1 for row1.

Is this possible or would it just be easier to create a line of code for each possible case?

I hope this makes sense, and thanks in advance for anyone that can shed any light!

+2  A: 

Why not just create one UIImageView in Interface Builder and then swap out the image it's displaying depending on your picker index?

Implement:

- (void)pickerView:(UIPickerView *)pickerView 
      didSelectRow:(NSInteger)row 
       inComponent:(NSInteger)component
{
    [imageView setImage:[imagesArray objectAtIndex:row]];
}

Where imageView is an instance variable (IBOutlet) connected to the image view control in Interface Builder.

Matt Long
note: you'd have to set up your image array prior to this with an array of UIImage objects.
Jesse Naugher
A: 

Ok, that makes sense.

I think what I was trying to do was take lazy loading to the extreme by only creating the uiImage object and the uiImageView object the first time it was called on from the picker (having clicked the "go" button).

I anticipate having around 40 images that will fill the screen.

Programatically, would this be an acceptable method for this number of images?

Thanks very for the responses guys.

GAJ