OGeek|极客世界-中国程序员成长平台

标题: ios - 如何使用 Segue 从 didFinishPickingMediaWithInfo 发送 UIImage? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:46
标题: ios - 如何使用 Segue 从 didFinishPickingMediaWithInfo 发送 UIImage?

所以我有什么:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info:[String : Any]) {
    let tempImage: UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    let imagetoTransmit: UIImage = tempImage
    shootedImage = imagetoTransmit
    self.performSegue(withIdentifier: "cameraSegueIdent", sender: nil)
    dismiss(animated: true, completion: nil)
}

哪里转:

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "cameraSegueIdent" {
        let imageToTransmit: UIImage = shootedImage
        let viewController = (segue.destination as! TakenPhotoPreviewViewController)
        viewController.takenImage = imageToTransmit
    } 
}

图像正在发送,但 Segue 没有执行。
请帮助!

更新

我的想法是将图像作为发送者发送,而不保存在当前的 ViewController 中,它就像一个魅力!

  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info:[String : Any]) {

    let tempImage: UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    self.dismiss(animated: true) {
    self.performSegue(withIdentifier: "cameraSegueIdent", sender: tempImage)
    }
}



Best Answer-推荐答案


以下可能会有所帮助。

    let tempImage: UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage
    let imagetoTransmit: UIImage = tempImage
    shootedImage = imagetoTransmit
    _ picker.dismissViewControllerAnimated(true, completion: {
        self.performSegue(withIdentifier: "cameraSegueIdent", sender: nil)
    })

另外,请确保在 Storyboard中正确配置了 segue 标识符。

关于ios - 如何使用 Segue 从 didFinishPickingMediaWithInfo 发送 UIImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39919866/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) Powered by Discuz! X3.4