使用未解析的标识符' info'

时间:2015-11-27 16:04:59

标签: ios swift2

我正在尝试从库中显示图像,但不断收到错误"在功能imagePickerController下使用未解析的标识符''"其中"如果让image = info [......."

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet weak var imagePickerView: UIImageView!
let imagePicker = UIImagePickerController()
override func viewDidLoad() {
    super.viewDidLoad()
    imagePicker.delegate = self
    // Do any additional setup after loading the view, typically from a nib.
}


func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage{
        self.imagePickerView.contentMode = .ScaleAspectFill
        self.imagePickerView.image = image
    }
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func pickerButton(sender: AnyObject) {
    let imagePicker = UIImagePickerController()
    imagePicker.delegate = self
    self.imagePicker.presentViewController(imagePicker, animated: true, completion: nil)
    self.dismissViewControllerAnimated(true, completion: nil)
}

}

1 个答案:

答案 0 :(得分:1)

你没有任何名为info的变量,也许你是editingInfo

我认为你的功能应该是这样的:

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
    if let info = editingInfo, image = info[UIImagePickerControllerOriginalImage] as? UIImage{
        self.imagePickerView.contentMode = .ScaleAspectFill
        self.imagePickerView.image = image
    }
}