Objective-C方法'imagePickerController:didFinishPickingMediaWithInfo:'

时间:2015-04-24 22:47:09

标签: swift

Objective-C方法'imagePickerController:didFinishPickingMediaWithInfo:'由方法提供'imagePickerController(:didFinishPickingMediaWithInfo :)'与协议'UIImagePickerControllerDelegate'中的可选需求方法'imagePickerController(:didFinishPickingMediaWithInfo :)'冲突/ p>

代码如下。怎么了?使用Xcode 6.4 Beta。

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary!) 

4 个答案:

答案 0 :(得分:9)

升级到swift 2.0后出现此错误。易于修复,只需重新键入此方法,然后自动完成将指导参数类型的更改。现在它应该是:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo: [String: Anyobject]) {

答案 1 :(得分:3)

您可以尝试修改方法,如下所示: func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject: AnyObject])

这是使用此委托的完整示例:

  func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject: AnyObject]) {

    var image: UIImage!

    // fetch the selected image
    if picker.allowsEditing {
      image = info[UIImagePickerControllerEditedImage] as! UIImage
    } else {
      image = info[UIImagePickerControllerOriginalImage] as! UIImage
    }

    // Do something about image by yourself

    // dissmiss the image picker controller window
    self.dismissViewControllerAnimated(true, completion: nil)

  }

答案 2 :(得分:1)

这对我有用。

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        imageView.contentMode = .ScaleAspectFit
        imageView.image = pickedImage
    }

    dismissViewControllerAnimated(true, completion: nil)
}

答案 3 :(得分:-1)

您的问题的正确功能格式是,

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
    {
        // Add your functionality here
    }