I need your help please.
I have two different view controllers:
1. with a button
2. with an image view.
I’m trying to pass the button’s image to the image view at the second view controller.
The prepareforsegue is being called but the image does not pass.
I attached my code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"pushGuessLogo"])
{
GeneralGuess *vc = [segue destinationViewController];
[self setLogoImageView:[[UIImageView alloc] initWithImage:self.logoImageSelected.imageView.image]];
[vc setImageGuessView:self.logoImageView];
}
}
ImageGuessView is the outlet of the image view at view controller number 2.
Thank you
Someone answered this the other day but I’m too lazy to find the link. (wouldn’t it be great if SO also had a Knowledge Base which questions get promoted to, rather than endless questions that do not come up in a search).
The gist is that the viewController’s view hierarchy is not yet set up at the point of
prepareForSegue, so yourImageGuessViewis nil at that point. What you can do is define aUIImageproperty on yourGeneralGuessclass and set that. Then inviewWillAppearload that image into yourImageGuessView.