简体   繁体   English

单击图像时,IOS segue无法正常工作

[英]IOS segue is not working when clicking on an Image

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. 但是,尽管segue具有正确的标识符,但单击图像视图时没有任何反应。

Please check the below screenshot 请检查以下屏幕截图 在此处输入图片说明

Could you help me please? 请问你能帮帮我吗?

I appreciate your time and efforts. 感谢您的辛勤工作。

Regards, 问候,

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. 尽管在我看来,可以从UIImageView (尽管不是直接从IB)执行序列化,但将替换为UIButton并设置图像要简单得多。

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 . 然后,根据发布的代码,您可以删除旧的segue, 按住 ctrl键并从按钮拖动到目标控制器,选择“ push”,然后将segue标识符设置为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 ). 这里应该注意的是, UIImageView (不同于其祖先UIView )的userInteractionEnabled属性默认情况下设置为NO在此处了解更多 )。 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 ). 因此,如果您选择直接从UIImageView处理任何事件,请确保将其切换为YES这是与此类似的答案 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM