当使用 UIImagePickerController 更改图像时,图像发生变化然后应用程序返回到上一页?

When changing an image with UIImagePickerController the image changes then the app goes back to previous page?

我正在努力更改 xcode 上的头像。我设法让应用程序使用 IOS 上照片库中的照片更改 UIImageView 但是当我 select 图像时,它会更改然后倒退到 UIViewController/previous 视图。

我不确定它为什么这样做以及我在代码中哪里出错了?有人可以帮忙吗?

import UIKit

class ProfileScreenVC: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {


    @IBOutlet var imgProfilePic: UIImageView!

    @IBAction func ChangeProfile(_ sender: AnyObject)
    {
        let PPimage = UIImagePickerController()
        PPimage.delegate = self
        PPimage.sourceType = UIImagePickerController.SourceType.photoLibrary
        PPimage.allowsEditing = false
        self.present(PPimage, animated: true)
        {
            // After it is complete
        }
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
        {
            if let PPimage = info [UIImagePickerController.InfoKey.originalImage] as? UIImage
            {
            imgProfilePic.image = PPimage
            }else{
                //Error Message
            }

            self.dismiss(animated: true, completion: nil)
        }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Make image circular
        imgProfilePic.roundedImages()

        // Do any additional setup after loading the view.
    }


}

当这种情况发生时,我也得到了这个error/output。

发现扩展时遇到错误:Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

而不是解散你的UIViewController解散只是UIImagePickerController(在这种情况下你可以使用方法参数之一:picker

picker.dismiss(animated: true, completion: nil)