0
我看了很多解決方案,可悲的是,沒有爲我工作。我用這個代碼來創建一個imagePickerController:UIImageView沒有顯示來自imagePickerController的圖片
@IBAction func takePhoto(sender: UIButton) {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera
imagePicker.mediaTypes = [kUTTypeImage as String]
imagePicker.allowsEditing = false
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, _didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
imageView.contentMode = .ScaleAspectFit
imageView.image = pickedImage
dismissViewControllerAnimated(true, completion: nil)
}
但仍然我在相機上的圖像不顯示在imageView中。我還導入了正確的代表。當我嘗試將imageView.image打印到控制檯時,它會返回nil
。我究竟做錯了什麼?
嘗試'FUNC imagePickerController(_選擇器:的UIImagePickerController,didFinishPickingMediaWithInfo信息:[字符串:AnyObject]){' –
作品!下劃線爲了使其工作而做了什麼? –
您的方法聲明需要與picker委託方法完全相同,否則將永遠不會被調用。您應該始終讓Xcode爲您自動完成它。 –