Reputation: 199
I have a view with an Image View, when the user clicks on it, I want to load the image inside it in a separate view.
This is my segue:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"Show Player Information"]){
if ([segue.destinationViewController isKindOfClass:[PlayerViewController class]]){
PlayerViewController *playerViewController = (PlayerViewController*)segue.destinationViewController;
[playerViewController setPlayer:[self.team.players objectAtIndex:self.tableView.indexPathForSelectedRow.row]];
}
}else if([segue.identifier isEqualToString:@"Show Image"]) {
if ([segue.destinationViewController isKindOfClass:[ImageViewerViewController class]]){
ImageViewerViewController *imageViewerViewController = (ImageViewerViewController*)segue.destinationViewController;
[imageViewerViewController setImageName:@"France.jpg"];
}
}
}
But nothing happens when clicking on the image view though the segue has the correct identifier.
Please check the below screenshot
Could you help me please?
I appreciate your time and efforts.
Regards,
Upvotes: 0
Views: 330
Reputation: 35636
Although it is possible to perform a segue from a UIImageView
(although not directly from IB) in my opinion is much simpler to just replace it with a UIButton
and set its image instead.
Then, based on your posted code, you could just remove your old segue, ctrl+drag from the button to your destination controller, choose 'push' and then set the segue identifier to Show Image
.
It should be noted here that UIImageView
(unlike its ancestor UIView
) has its userInteractionEnabled
property set to NO
by default (more about it here). So if you choose to handle any events directly from the UIImageView
make sure that you switch it to YES
(here is a similar answer regarding this).
Upvotes: 1