Tim Stullich
Tim Stullich

Reputation: 251

prepareForSegue not working as expected

I have set up a view in which a user can pick a photo and then use it as their profile picture. Once they picked the image a UIImageView is supposed to be updated. I use the prepareForSegue method in order to pass the information on to the view controller which contains the image view. However, the image never gets updated when I pass something forwards. This is my code:

 -(void)prepareForSegue(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"UploadSuccessSegue"]) {  
       UploadSuccessViewController *usv = (UploadSuccessViewController *)  
       [segue destinationViewController];  
       usv.bookView.image = self.uploadedImage.image;
    }
  }

Any help help would be greatly appreciated.

Upvotes: 1

Views: 1138

Answers (1)

Rob
Rob

Reputation: 437552

Yep, GTSouza hit the nail on the head. So you want to create a property to hold your UIImage reference in UploadSuccessViewController.h, e.g.:

@property (nonatomic, strong) IUImage *bookImage;

then your prepareForSegue can populate it:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"UploadSuccessSegue"]) {  
        UploadSuccessViewController *usv = [segue destinationViewController];  
        usv.bookImage = self.uploadedImage.image;
    }
}

Then the UploadSuccessViewController viewDidLoad can use it:

self.bookView.image = self.bookImage;

Upvotes: 2

Related Questions