我有一个UITableViewCell
按钮来拍摄一个图像并把它放回单元格中。当我调用UIImagePickerController
并获取图像时,它不会调用以下委托:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject], sender:AnyObject)
这是我的takePhotoFunction
in UITableViewController
@IBAction func takePhoto(sender: AnyObject) {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
imagePickerController.allowsEditing = true
let actionSheet = UIAlertController(title: "Choose image souruce", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
actionSheet.addAction(UIAlertAction(title: "Take Image", style: UIAlertActionStyle.Default, handler: { (alert:UIAlertAction!) -> Void in
imagePickerController.sourceType = UIImagePickerControllerSourceType.Camera
self.presentViewController(imagePickerController, animated: true, completion: nil)
}))
actionSheet.addAction(UIAlertAction(title: "Photo Library", style: UIAlertActionStyle.Default, handler: { (alert:UIAlertAction!) -> Void in
imagePickerController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(imagePickerController, animated: true, completion: nil)
}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(actionSheet, animated: true, completion: nil)}
发布于 2016-09-25 13:45:33
在Swift 3中,这个委托方法现在称为:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
不同之处是:
我也有同样的问题,当我做这些改变时,它起了作用。
发布于 2017-03-08 06:43:39
UIImagePickerControllerDelegate,UINavigationControllerDelegate
1.别忘了添加
viewDidLoad()
2.在中添加 picker.delegate = self
3.添加委托方法
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
userImageView.contentMode = .scaleAspectFit
userImageView.image = chosenImage
dismiss(animated:true, completion: nil)
}
public func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {self.dismiss(animated: true, completion: nil)
}
希望它有帮助:)
发布于 2019-02-01 07:26:10
为“迅速”4.2
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let chosenImage = info[.originalImage] as? UIImage{
//use image
}
}
https://stackoverflow.com/questions/29189548
复制相似问题