Pergunta

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");
}

}

Foi útil?

Solução

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

Outras dicas

You can't do this because it isn't ready yet.

cvc.desktopview.image = image;

Instead you need to store it in a UIImage property and use it in viewDidLoad method of your destination view controller.

Something like this in prepareForSegue

cvc.image = image;

and in the view controller

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.desktopview.image = image;


}

Edit:

You need this at your view controller's header file.

@property (nonatomic, strong) UIImage * image;

ViewDidLoad is called only after ALL outlets are loaded, so never try to set outlet/views value in prepare segue method, as viewDidLoad will be called after prepare segue method. Now you can do one that create an UIImage property in filterViewController and set its value. and In viewDidLoad method set it to specfic imageView.

Optimized way

 [segue.destinationViewController setAnotherImage:yourImage];

Another view controller

-(void)setAnotherImage:(UIImage *)happiness
{
    //get your image here
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top