尝试使用以下功能时
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不起作用并抛出错误。
帮助!
答案 0 :(得分: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
}
答案 1 :(得分: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)
}