Can't get UIImageView to show


I can’t get the UIImageView to show on the screen - neither in the simulator or on the phone. I have made the connection from File’s owner, checked the code multiple times and spent about a gazillion hours on trying to find the issue.

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[imageView setImage:image];
[self dismissModalViewControllerAnimated:YES];

Any pointers what I could be doing wrong? I also tried to put my own image on the screen and this does not work either:

imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@“Dice.png”]];



I was having the same problem.

What’s happening is that after the UIImagePickerController gets loaded, it’s triggering a low memory warning. Remember that when a low memory warning gets called, it sends a message to all of the views telling them to free up memory (which runs viewDidUnload)

Inside of viewDidUnload for ItemDetailViewController there is a call to unload the imageView instance variable

[imageView release];
imageView = nil;

So then when imagePickerController:didFinishPickingMediaWithInfo goes to set the image to the imageView variable, it’s already nil, so nothing happens. In order to fix this you need to move the line:

[self dismissModalViewControllerAnimated:YES];


[imageView setImage:image];

so that ItemDetailViewController gets loaded (and consequentially the imageView variable) before it tries to set the image