StuartM
StuartM

Reputation: 6823

Image Picker and pushing image selected to a new view controller

I am trying to use the Camera to take a photo then pass the selected photo onto another View Controller. I use a segue to push the image to the next but it does not seem to get an image.

pragma mark - UIImagePickerDelegate Methods

//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 - Prepare for Segue

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

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

Upvotes: 0

Views: 1137

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89569

I'm guessing "photoAreaVC.photoImageView" is still null as the destinationViewController hasn't been fully instantiated yet.

And you can confirm this by adding this line in your "prepareForSegue:" method:

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

You need to find a place (e.g. a "UIImage" property in the destination view controller, perhaps?) to temporarily stash that image until "viewDidAppear:" or "viewWillAppear:" gets called, somewhere where the "photoImageView" property points to a valid object.

Upvotes: 2

Related Questions