UIImageView无法反映设置.image属性的更改

时间:2019-08-27 06:39:08

标签: swift uiimageview uiimage uiimagepickercontroller

当我尝试通过imagePickerControllermyImageView.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)
    }
}

0 个答案:

没有答案