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];
}

pragma mark - 为 Segue 做准备

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

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

1 回答 1

2

我猜“ photoAreaVC.photoImageView”仍然为空,因为destinationViewController 还没有完全实例化。

prepareForSegue:您可以通过在您的 " " 方法中添加这一行来确认这一点:

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

您需要找到一个位置(例如UIImage,目标视图控制器中的“”属性,也许?)来临时存储该图像,直到“ viewDidAppear:”或“ viewWillAppear:”被调用,“ photoImageView”属性指向有效对象的地方。

于 2013-07-12T16:19:46.533 回答