当我尝试通过imagePickerController
在myImageView.image = UIImage(named: "account_icon")
范围内更改图像视图时,什么都没有发生。但是,当我在viewDidLoad
函数中执行此操作时,它将起作用。
我非常困惑,因为我也尝试在主线程中使用self.myImageView.image
而不是用myImageView.image
来分配它,而是尝试使用myImageView.setNeedsDisplay()
class AccountVC: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
let imagePicker = UIImagePickerController()
@IBOutlet weak var myImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
myImageView?.image = UIImage(named: "checkmark")
}
//...
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let selectedImage = info[.originalImage] as? UIImage else {
print("error")
return
}
self.myImageView?.image = UIImage(named: "account_icon") //just testing with image in assets rather than from photoLibrary
self.myImageView?.setNeedsDisplay()
print("out of scope")
self.dismiss(animated: true, completion: nil)
}
}