I have two View Controllers: 1. With two buttons with different images. 2. With an UIImageView.
I'm trying to pass the image of the selected button at VC1 to the Image View at VC2 with an outlet collection without having to declare an IBoutlet for each button.
I'm using the following code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"pushGuessLogo"])
{
GeneralGuess *vc = [segue destinationViewController];
NSInteger buttonId = [[sender title] intValue];
[self setLogoImageView:[[buttons objectAtIndex:buttonId] imageView]];
[vc setTransferedImage:self.logoImageView.image];
}
}
The titles of the buttons are 0 and 1. The result is that when I press button 0 the image of 1 is being passed and when I press button 1, no image is being passed
Thank you
Why do you bother with the button title? Just get the image view straight from sender, which is a UIButton in this case.
You'd use the following code:
[(UIButton*)sender imageView]
To get the image view property of the sender.