我有一个UIImagePickerController所以当用户选择他/她的照片时,segue被执行但segue不工作(实际上正在工作但没有加载vc),这是我的代码:

        let imagepicker = UIImagePickerController()

        imagepicker.delegate = self

        imagepicker.sourceType = UIImagePickerControllerSourceType.photoLibrary

        imagepicker.allowsEditing = true

        self.present(imagepicker, animated: true)
        //...
        func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
            takenimage = info[UIImagePickerControllerOriginalImage] as! UIImage
            self.dismiss(animated: true, completion: nil)
            print("image loaded")
            performSegue(withIdentifier: "ToPrescriptionView", sender: nil)
        }
        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          if segue.identifier == "ToPrescriptionView" {
          let PrescriptionView = segue.destination as! Prescription
          PrescriptionView.PrescriptionImage = takenimage
         print("segue loaded")
        }

我得到“图像加载”和“segue加载”,但我的viewcontroller仍然是前一个

最佳答案

当您退出performSegue时,尝试在dismiss的完成块中UIImagePickerController

self.dismiss(animated: true) {
     performSegue(withIdentifier: "ToPrescriptionView", sender: nil)
}

关于swift - 我的segue无法在图像选择器中工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41341323/

10-14 22:27