到目前为止,这是我的代码:
/* 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;
}
所以基本上我试图从iPhone相机中获取照片并将其显示在UIImageView中。只要myViewController类显示为独立视图,这就完美无缺。如果我将View放在UINavigationController中,UIImageView在使用相机拍摄之后将不会显示图像。但如果我从图书馆中选择一张图片,一切都会好起来的。
那么为什么UIImageView不会在UINavigationController中显示用相机拍摄的图像?
答案 0 :(得分:0)
尝试切换以下行:
[thePicker dismissModalViewControllerAnimated:YES];
UIImage *img = [imageInfo objectForKey:@"UIImagePickerControllerOriginalImage"];
self.myImageView.image = img;
以下内容:
UIImage *img = [imageInfo objectForKey:@"UIImagePickerControllerOriginalImage"];
self.myImageView.image = img;
[thePicker dismissModalViewControllerAnimated:YES];
也许是因为在使用
保留视图之前解除了视图而释放了图像self.myImageView.image = img;
答案 1 :(得分:0)
在我看来你是在解雇错误的viewcontroller。不应:
[thePicker dismissModalViewControllerAnimated:YES];
读:
[self dismissModalViewControllerAnimated:YES];