0

我想使用相机拍照,然后将选定的照片传递到另一个视图控制器。我使用segue将图像推送到下一个,但它似乎没有获取图像。图像选择器和推送图像选择到一个新的视图控制器

编译马克 - UIImagePickerDelegate方法

//delegate methode will be called after picking photo either from camera or library 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

    [self.collectedImageView setImage:image]; 

    [self performSegueWithIdentifier:@"photoArea" sender:self]; 
} 

编译标志 - 准备Segue公司

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    MESSelectPhotoAreaViewController *photoAreaVC = [segue destinationViewController]; 

    photoAreaVC.photoImageView.image = self.collectedImageView.image; 
} 

回答

2

我猜 “photoAreaVC.photoImageView” 仍然是null作为destinationViewController还尚未完全实例化。

而且你可以在你的“prepareForSegue:”的方法加入这一行证实了这一点:(?例如“UIImage”属性的目的地视图控制器,也许)

if (photoAreaVC.photoImageView == NULL) 
    NSLog(@"photoImageView doesn't yet exist"); 

你需要找到一个地方暂时存储该图像,直到“viewDidAppear:”或“viewWillAppear:”被调用,其中“photoImageView”属性指向有效对象的某处。

+0

100%正确。我实际上并没有在第一个实例中需要UIImageView,所以我将其更改为图像,然后将图像传递到新的控制器图像实例,并使用viewDidAppear更新了图像视图。谢谢 – StuartM

+0

目前我的应用程序存在这个问题,而这个答案是迄今为止我找到的最好的答案。尽管出于兴趣,我将如何“暂时”隐藏我的形象,即。我可以在哪里做什么代码? – SixtySticks

+0

一个临时(或永久)存储位置可能是您的对象的“UIImage”属性。 –