我正在尝试使用相机拍摄照片,然后将所选照片传递到另一个视图控制器。我使用segue将图像推到下一个,但它似乎没有得到图像。
//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];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
MESSelectPhotoAreaViewController *photoAreaVC = [segue destinationViewController];
photoAreaVC.photoImageView.image = self.collectedImageView.image;
}
答案 0 :(得分:2)
我猜“photoAreaVC.photoImageView
”仍然为null,因为目标viewController还没有完全实例化。
您可以通过在“prepareForSegue:
”方法中添加此行来确认:
if (photoAreaVC.photoImageView == NULL)
NSLog( @"photoImageView doesn't yet exist" );
您需要在目标视图控制器中找到一个地方(例如“UIImage
”属性,或许?)暂时将该图像存储到“viewDidAppear:
”或“viewWillAppear:
”被调用,在“photoImageView
”属性指向有效对象的地方。