gpt4 book ai didi

swift - UIImagePickerController didFinishPickingImage 不在 Swift 3 中调用

转载 作者:搜寻专家 更新时间:2023-10-30 22:03:41 27 4
gpt4 key购买 nike

我正在尝试使用 imagePickerView 从照片库加载图像。我更新了我的 plist 以访问 Xcode 8 的照片库,如下所示。

enter image description here

之后,更新了 plist。我可以访问照片库。但是,Picker 图像没有加载到我的 imageView。

我的代码:

注意:下面的代码用于在 Xcode 7 而不是在 Xcode 8 中工作?

   import UIKit

class ViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {

let imagePicker = UIImagePickerController()
@IBOutlet weak var imageView: UIImageView!

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

@IBAction func library(_ sender: UIButton) {

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
}
}

代码已更新: 来自 rmaddy 的回答:

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
imageView.image = image
}
picker.dismiss(animated: true, completion: nil);
}

enter image description here

提前致谢....

最佳答案

在 Swift 3 中,您需要使用正确的委托(delegate)方法:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
imageView.image = image
}

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

关于swift - UIImagePickerController didFinishPickingImage 不在 Swift 3 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40112816/

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