0

尝试使用以下功能时

func imagePickerController(picker: UIImagePickerController,didFinishPickingImage image: UIImage, editingInfo: [String: AnyObject]?) {
    let selectedImage:UIImage = (editingInfo[UIImagePickerControllerOriginalImage]) as! UIImage
    displayImage.image = selectedImage
    self.dismissViewControllerAnimated(true, completion: nil)
}

出现错误:“无法下标 '[String:AnyObject] 类型的值?具有 'String' 类型的索引

在第二行我写了 let selected Image

这在 Xcode 6.3 和 6.4 上运行良好,但现在使用新的 Xcode 7 beta 4 不起作用并引发错误。

帮助!

4

2 回答 2

0

我在 imagePickerController 的文档中找到了答案。我不得不使用的方法是 didFinishPickingMediaWithInfo ,如下所示:

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

    let selectedImage:UIImage = (info[UIImagePickerControllerOriginalImage]) as! UIImage
    displayImage.image = selectedImage
    self.dismissViewControllerAnimated(true, completion: nil)
}
于 2015-07-22T17:25:53.930 回答
0

在将图像设置为 imageView 之前尝试关闭控制器。
将您的方法替换为:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
 self.dismissViewControllerAnimated(true, completion: nil)
let selectedImage:UIImage = (editingInfo[UIImagePickerControllerOriginalImage]) as! UIImage
displayImage.image = selectedImage

}
于 2015-07-22T13:35:37.917 回答