UIImagePickerController:didFinishPickingMediaWithInfo 未被调用 [英] UIImagePickerController: didFinishPickingMediaWithInfo not being called
本文介绍了UIImagePickerController:didFinishPickingMediaWithInfo 未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
希望你们一切顺利.想知道是否有人可以帮助我理解为什么 Xcode 不能和我一起玩......
Hope you're all doing well. Wondered if anyone could help me understand why Xcode fails to play nice with me....
我已将代码分解为以下部分,以便我从 UIImagePicker 中选择个人资料照片:
I have broken the code into sections below in order to allow me to select a profile photo from UIImagePicker:
- 作品:为 ImagePicker & 分配委托类导航控制器
- 工作:实例化 UIImagePicker 变量
- 作品:加载 ImagePickerViewController 并启用选择图像
- FAILS:添加了用于使用 UIImagePicker 关闭和完成拾取的附加功能,但两者都没有被调用?我做错了什么?
提前致谢!
class ProfileVC: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var imagePicker: UIImagePickerController!
<小时>
override func viewDidLoad() {
super.viewDidLoad()
imagePicker = UIImagePickerController()
imagePicker.delegate = self
}
<小时>
@IBAction func selectPhotoPressed(sender: UITapGestureRecognizer) {
if UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) {
self.imagePicker.sourceType = .PhotoLibrary
} else {
self.imagePicker.sourceType = .Camera
}
imagePicker.allowsEditing = true
imagePicker.mediaTypes = [kUTTypeImage as String]
self.presentViewController(imagePicker, animated: true, completion: nil)
}
<小时>
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
self.dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo image: UIImage, editingInfo: [String : AnyObject]?) {
headerView.profilePhoto.contentMode = .ScaleAspectFill
headerView.profilePhoto.image = image
imagePicker.dismissViewControllerAnimated(true, completion: nil)
uploadImage(image)
}
推荐答案
好的,我现在似乎可以运行了,感谢您帮助确定代码是古老的 ;) 以下是现在运行的内容:
OK I seem to have it working now, thanks for your help in identifying that the code was ancient ;) Here is what now runs:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
headerView.profilePhoto.contentMode = .ScaleAspectFit
headerView.profilePhoto.image = image
imagePicker.dismissViewControllerAnimated(true, completion: nil)
uploadImage(image!)
}
这篇关于UIImagePickerController:didFinishPickingMediaWithInfo 未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文