gpt4 book ai didi

ios - UIImagePickerController 不能在 Swift 中工作

转载 作者:行者123 更新时间:2023-11-28 14:47:41 25 4
gpt4 key购买 nike

当我通过 UIImagePickerController 选择图像时,我在 xCode 中得到以下输出:

[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

这是我的代码:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
imagePicked = image

dismiss(animated: true, completion: nil)
performSegue(withIdentifier: "showImage", sender: self)
}

ViewController 类已按应有的方式声明:

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

let imagePickerController = UIImagePickerController()
var imagePicked = UIImage()

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
imagePickerController.delegate = self

}

我使用按钮打开 ImagePicker:

@IBAction func chooseImageBtn(_ sender: Any) {
imagePickerController.sourceType = .photoLibrary
self.present(imagePickerController, animated: true, completion: nil)

}

当我在模拟器中启动应用程序时,我可以单击按钮并选择一个图像,但随后选择器会关闭并且 Xcode 中会显示此消息:

2018-05-01 16:50:01.214450+0200 Awesome Name[57575:12752181] [MC] Reading from private effective user settings.

2018-05-01 16:50:03.740711+0200 Awesome Name[57575:12752241] [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

我已经做了一些研究,但没有任何效果。 ImagePicker的delegate设置为self,我也试过在func imagePickerController(_ picker: 之前添加@objc,但没有解决问题。

我还能尝试什么来显示所选图像?

最佳答案

尝试删除 performeSegue功能,如果你真的需要使用它,只需将它添加到 completiondismiss功能。

关于ios - UIImagePickerController 不能在 Swift 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50119459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com