图像文件更改后 Swift 刷新 UIImageView
Refresh UIImageView in Swift after Image File Has Changed
在我的应用程序中,我将 UIImageView
的图像设置如下:
override func viewWillAppear(animated: Bool) {
// ...
self.currentPlayer.image = UIImage(named: appDelegate.appSupportDirectory.stringByAppendingPathComponent(currentPlayer!.id!.UUIDString + ".jpg"))
}
换一种说法,我允许用户更改图像,即用新文件替换文件,同时保留名称。当我 return 到这个视图时,旧图片仍然显示。即使我在两者之间加载不同的播放器配置文件,该应用程序似乎也能记住过时的图片。如何强制 UIImageView
刷新?
已找到解决方案。将代码更改为:
override func viewWillAppear(animated: Bool) {
// ...
self.currentPlayer.image = UIImage(contentsOfFile: appDelegate.appSupportDirectory.stringByAppendingPathComponent(currentPlayer!.id!.UUIDString + ".jpg"))
}
在我的应用程序中,我将 UIImageView
的图像设置如下:
override func viewWillAppear(animated: Bool) {
// ...
self.currentPlayer.image = UIImage(named: appDelegate.appSupportDirectory.stringByAppendingPathComponent(currentPlayer!.id!.UUIDString + ".jpg"))
}
换一种说法,我允许用户更改图像,即用新文件替换文件,同时保留名称。当我 return 到这个视图时,旧图片仍然显示。即使我在两者之间加载不同的播放器配置文件,该应用程序似乎也能记住过时的图片。如何强制 UIImageView
刷新?
已找到解决方案。将代码更改为:
override func viewWillAppear(animated: Bool) {
// ...
self.currentPlayer.image = UIImage(contentsOfFile: appDelegate.appSupportDirectory.stringByAppendingPathComponent(currentPlayer!.id!.UUIDString + ".jpg"))
}