Search code examples
iosobjective-cuiviewcontrolleruiimageuistoryboardsegue

Pass image from one view to another view by preparesegue?


I am trying to pass image from one viewcontroller to another . I have tried all available solutions on stackoverflow , still i am struggling with the same. How can i pass uiimage through preparesegue ??

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ( [segue.identifier isEqualToString:@"filter"]) {
    FilterViewController *cvc = [segue destinationViewController];
    UIImage *image = imageView.image;
    cvc.desktopview.image = image;
    NSLog(@"segue");
}

}


Solution

  • Go to FilterViewController.h

    add a uiimage there @property(nonatomic,strong)UIImage *dvImage;

    Go to FilterViewController.m

    Synthesize it @synthesize dvImage;

    Go to the code Where you are calling the FilterViewController

    FilterViewController *cvc = [segue destinationViewController];
    UIImage *image = imageView.image;
    cvc.setDvImage = image;
    NSLog(@"segue");
    

    and then in viewDidLoad set self.desktopview.image = dvImage;

    Don't forgot to check the segue identifier

    Hope this helps