A quick iPhoneOS Development tip today, loading an image resource into a UIImageView field.

I had created a UIImageView in Interface Builder, but I wanted the image to change every time the page appears.

In interface builder I have linked a UIImageView to the IBOutlet recipeImage

I use the following code to load up a new image:

//Load Image <br />
NSString *recipeImageFileName = [temperatureDictionary objectForKey:@"Image"];   //Get Image Name as String (no extension) <br />
UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:recipeImageFileName ofType:@"jpg"]]; //load the image into memory, adapt the parameters (filename, extension) as per needs <br />
[recipeImage setImage:img];  //show the image in the UIImageView


Super simple!