首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >didFinishPickingMediaWithInfo未调用

didFinishPickingMediaWithInfo未调用
EN

Stack Overflow用户
提问于 2015-03-22 00:14:47
回答 12查看 17.5K关注 0票数 22

我有一个UITableViewCell按钮来拍摄一个图像并把它放回单元格中。当我调用UIImagePickerController并获取图像时,它不会调用以下委托:

代码语言:javascript
运行
复制
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject], sender:AnyObject)

这是我的takePhotoFunction in UITableViewController

代码语言:javascript
运行
复制
@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)}
EN

回答 12

Stack Overflow用户

回答已采纳

发布于 2016-09-25 13:45:33

Swift 3中,这个委托方法现在称为:

代码语言:javascript
运行
复制
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])

不同之处是:

  1. 在选择器之前有一个下划线_
  2. 最后的信息类型从String : AnyObject改为String : Any

我也有同样的问题,当我做这些改变时,它起了作用。

票数 43
EN

Stack Overflow用户

发布于 2017-03-08 06:43:39

UIImagePickerControllerDelegate,UINavigationControllerDelegate 1.别忘了添加

viewDidLoad() 2.在中添加 picker.delegate = self

3.添加委托方法

代码语言:javascript
运行
复制
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)
}

希望它有帮助:)

票数 17
EN

Stack Overflow用户

发布于 2019-02-01 07:26:10

为“迅速”4.2

代码语言:javascript
运行
复制
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
   if let chosenImage = info[.originalImage] as? UIImage{
        //use image
    }
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29189548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档