ophychius - 10 months ago 45
iOS Question

# UIImageView does not show Image from UIImagePickerController

I am trying to take a picture with my app and then show it in a UIImageView that is predefined in my .xib. I have a IBOutlet UIImageView *_foto that is linked to the UIImageView in the .xib

When I do the following the picture doesnt show in the UIImageView after taking a picture:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{

_foto.image = image;
//Also tried set image, and resizing the image first

[self dismissModalViewControllerAnimated:YES];

}


Now, when I add code to create a new image view with the image returned from my picker, and add that as a subView to my view like this, something strange happens:

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{

UIImageView *iv = [ [UIImageView alloc] initWithImage:image];

[iv release];

_foto.image = image;

[self dismissModalViewControllerAnimated:YES];
}


Now the image shows in both the newly created image view in the left top corner of my view,as expected, but also in my _foto UIImageView. This has me seriously confused, and I have no idea what is going on, all i know is that it is not the behavior i expected. Does anyone have any clue, and hopefully a proper solution for this problem?

UIImagePickerController grab a lot of device memory while picking an image. During - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo I've noticed many times memory warnings level 1 and 2. It may cause force unload and reload your view, launch viewDidLoad method of your view controller again. If your _foto object is an IBOutlet it will be removed from memory and load again with start values of all properties (image too). Also if you set image to nil in viewDidLoad it may be a reason.