图像文件更改后,在Swift中刷新UIImageView

时间:2015-08-02 18:16:23

标签: ios swift uiimageview

在我的应用中,我按如下方式设置UIImageView的图像:

override func viewWillAppear(animated: Bool) {
    // ...
    self.currentPlayer.image = UIImage(named: appDelegate.appSupportDirectory.stringByAppendingPathComponent(currentPlayer!.id!.UUIDString + ".jpg"))
}

在另一个视图中,我允许用户更改图像,即在保留名称的同时用新文件替换文件。当我返回此视图时,仍会显示旧图片。该应用似乎记得过时的图片,即使我在其间加载不同的播放器配置文件。如何强制UIImageView刷新?

1 个答案:

答案 0 :(得分:1)

找到解决方案。将代码更改为:

override func viewWillAppear(animated: Bool) {
    // ...
    self.currentPlayer.image = UIImage(contentsOfFile: appDelegate.appSupportDirectory.stringByAppendingPathComponent(currentPlayer!.id!.UUIDString + ".jpg"))
}