2
我試圖從畫廊到新的ViewController添加圖像,但得到一個錯誤如何分配圖片的UIImageView的(SWIFT 3)
Creating an image format with an unknown type is an error fatal error: unexpectedly found nil while unwrapping an Optional value
代碼:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let im = info[UIImagePickerControllerOriginalImage] as? UIImage {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "editImage") as! EditImageViewController
vc.imageView.image = im
self.present(vc, animated: true, completion: nil)
} else {
print("Something went wrong")
}
imagePicker.dismiss(animated: true, completion: nil)
}
我的錯誤是什麼?
要在此展開一般來說,沒有外部代碼應該直接訪問視圖控制器的視圖。外部代碼應該只向視圖控制器提供信息/數據。讓視圖控制器負責根據數據更新自己的視圖。這是MVC設計背後的要點之一。 – rmaddy
謝謝!有用。 – nik3212