ios - 将图像从主视图传递到另一个 View 问题

标签 ios uiimageview uiimagepickercontroller

我试图从图像库中选择一个图像,并在通过 UIImagePickerControllerOriginalImage 选择图像后将其传递到另一个 View ,但它不起作用。我总是在另一个页面中得到一个空的 UIImageView。我的问题可能是什么?

MainPageVeiwController.m:

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

    FormViewController *second = [[FormViewController alloc] initWithNibName:@"FormViewController" bundle:nil];

    [self dismissModalViewControllerAnimated:YES];

    [second.imageView setImage:[editingInfo objectForKey:UIImagePickerControllerOriginalImage]];

    [self.navigationController pushViewController:second animated:YES];
}

FormViewController.m:

@property (strong, nonatomic) IBOutlet UIImageView *imageView;

最佳答案

问题是在您尝试访问 imageView 时 FormViewController 的 View 尚未加载,因此它将为 nil。您应该在 FormViewController 中创建一个 UIImage 属性,然后传递图像。让 FormViewController 在 vi​​ewDidLoad 中填充它自己的 ImageView 。

关于ios - 将图像从主视图传递到另一个 View 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24868857/

相关文章:

ios - 将 UIImageView 高度更改为图像高度?

c# - MonoTouch 对话框部分中的纯文本?

ios - 在 Swift 中的 UIImagePickerController 之后,UIImage 为 nil

ios - UIImagePickerController 相机源内存不足

ios - 从照片库中选取图像

ios - 如何使用 Swift 在 XCode 中颠倒旋转 UILabel?

c++ - 如何在点击时更改 Sprite 图像

iphone - 如何使用 CIFeatures 将图像放在眼睛和嘴巴上

ios - 如何在 Obj C 中的 UIImageView 顶部绘制横幅

iphone - UIImagePickerController - 从应用程序文档目录保存和检索照片