UIImagePickerController didFinishPickingImage 未调用 Swift 3
UIImagePickerController didFinishPickingImage not calling in Swift 3
我正在尝试使用 imagePickerView 从照片库加载图像。我更新了我的 plist 以访问下面的照片库 Xcode 8.
更新后plist.I可以访问照片库。但是,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);
}
提前致谢....
在Swift3中你需要使用正确的委托方法:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
imageView.image = image
}
picker.dismiss(animated: true, completion: nil);
}
我正在尝试使用 imagePickerView 从照片库加载图像。我更新了我的 plist 以访问下面的照片库 Xcode 8.
更新后plist.I可以访问照片库。但是,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);
}
提前致谢....
在Swift3中你需要使用正确的委托方法:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
imageView.image = image
}
picker.dismiss(animated: true, completion: nil);
}