UIImageView not updating image

痞子三分冷 提交于 2019-12-06 15:46:46

Loading an UIImage with init(named:) caches the image. So as long as the image name does not change or the system is emptying the cache (for example when you restart the app) the image will be used from the cache and not loaded again.

Try to use init(contentsOfFile:) instead to load the image.

Try updating your imagePickerController method. You have used pickedImage as an instance variable and an local optional variable. I have used newImage instead.

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    if let newImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        profilepic.contentMode = .ScaleToFill
        profilepic.image = newImage
        pickedImage = newImage


        if let data = UIImagePNGRepresentation(newImage) {
                let filename = Operations.getDocumentsDirectory().stringByAppendingPathComponent("profile.png")
                data.writeToFile(filename, atomically: true)

        }
    }

    dismissViewControllerAnimated(true, completion: nil)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!