首页 > 解决方案 > 如何在选取图像后执行 Segue

问题描述

我想在用户选择图像后(通过单击图像视图)执行 segue。

我已经检查了 segue id 并成功地连接了两个视图控制器。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        // Executed when we select an image from the photo library.
        if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {

            // Sets the image to the image view (not really relevant because
            // we push the user to the DetailVC, but let's leave it).
            self.imageView.image = image

            // Closing the image picker.
            self.dismiss(animated: true, completion: nil)

            // Performing segue (It doesn't perform!).
            print("It gets to this point, but doesn't perform.")
            self.performSegue(withIdentifier: "showDetail", sender: nil)
        }
    }

该程序将图像设置为图像视图,在“执行”功能之后获取该打印语句,但不执行segue。

标签: iosswiftxcodesegue

解决方案


在情节提要中选择具有图像视图的视图控制器,在顶部有黄色圆圈右键单击从那里拖动到您想要继续的视图控制器并为其标识符提供 ID =“segueID”然后像这样编辑您的 didfinishpicking 方法

if let img = info[.originalImage] as? uiimage{
myimageview.image = img
dismiss(animated: true) {
self.performSegue(withIdentifier: “segueID”, sender: self)}}

推荐阅读