我的segue不在imagepicker中工作

时间:2016-12-27 08:03:23

标签: swift xcode swift3 segue uiimagepickercontroller

我有一个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 loaded"但我的viewcontroller仍然是前一个

1 个答案:

答案 0 :(得分:2)

当您解雇performSegue时,尝试在dismiss的完成区内UIImagePickerController。{/ p>

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