views:

259

answers:

2

This is my code so far:

/* class: myViewController
@interface myViewController: UIViewController
       <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
*/
- (IBAction) getPicture {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
       picker.delegate = self;
       picker.sourceType = UIImagePickerControllerSourceTypeCamera;
       [self presentModalViewController:picker animated:YES];
}

- (void) imagePickerController:(UIImagePickerController *)thePicker 
                    didFinishPickingMediaWithInfo:(NSDictionary *)imageInfo
{
    [[thePicker parentViewController] dismissModalViewControllerAnimated:YES];
       UIImage *img = [imageInfo
                           objectForKey:@"UIImagePickerControllerOriginalImage"];
    self.myImageView.image = img;
}

So basically I'm trying to get a photo from the iPhone camera and display it in a UIImageView. This works perfectly fine as long the class myViewController is displayed as a standalone view. If I'm putting the View inside a UINavigationController the UIImageView won't display the image after taking one with the camera. But if I choose a picture from the library everything is fine again.

So why does the UIImageView won't display a image taken with the camera inside a UINavigationController?

A: 

Try to switch the following lines:

[thePicker dismissModalViewControllerAnimated:YES];
UIImage *img = [imageInfo objectForKey:@"UIImagePickerControllerOriginalImage"];
self.myImageView.image = img;

to the following:

UIImage *img = [imageInfo objectForKey:@"UIImagePickerControllerOriginalImage"];
self.myImageView.image = img;
[thePicker dismissModalViewControllerAnimated:YES];

Perhaps the image is released because of the dismissing of the view before you retain it with

self.myImageView.image = img;
Shingoo
I have tried this without any luck.
dan
Have you tried the following after setting the image? [self setNeedsDisplay];
Shingoo
Unfortunately it doesn't change anything.
dan
A: 

Seems to me you're dismissing the wrong viewcontroller. Shouldn't:

[thePicker dismissModalViewControllerAnimated:YES];

read:

[self dismissModalViewControllerAnimated:YES];
pheelicks
I've just tried this but it doesn't make any difference. Could you explain this to me a little more? thePicker should be the current ImagePicker.
dan
thePicker is the current ImagePicker, but I think you're supposed to send the dismissModalViewControllerAnimated call to the view controller that created the modal view controller rather than the modal view controller itself
pheelicks