开发者

iPhone SDK - How to display a photo taken with the camera inside a UINavigationController?

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?


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;


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

[thePicker dismissModalViewControllerAnimated:YES];

read:

[self dismissModalViewControllerAnimated:YES];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜