应用程序打开pickerController并选择图像,但它不会显示所选的图像。我尝试在self
之前添加image_sel.image = photo
,但它既不起作用也不行。当我将print
放在扩展内部时,它会打印并且它也会遇到断点。
lazy var image_sel: UIImageView = {
let i = UIImageView()
i.translatesAutoresizingMaskIntoConstraints = false
i.image = #imageLiteral(resourceName: "noimage")
return i
}()
@objc func imageSelect(){
let pickerController = UIImagePickerController()
pickerController.delegate = self
present(pickerController, animated: true, completion: nil)
}
extension CameraPage: UIImagePickerControllerDelegate,UINavigationControllerDelegate {
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let photo = info["UIImagePickerControllerOriginalImage"] as? UIImage {
image_sel.image = photo
}
dismiss(animated: true, completion: nil)
}
}
答案 0 :(得分:0)
lazy var image_sel:UIImageView
您正在使用lazy var属性,当您尝试将值分配给ImageView时,可能仍然没有对象。
尝试在另一个UIImageView上使用该图像来查看是否存在问题。
答案 1 :(得分:0)
我还没有看到你展示image_sel
的地方。您使用的是addSubview
吗?