我正在使用我的应用程序,但我一度陷入困境。有一个UIIMAGEVIEW和一个UPLOAD按钮。因此,当用户单击“上传”按钮时,他会在选择图像后进入照片库以选择图像,我正在UIIMAGEVIEW上显示该图像。所以我的问题是:在UIIMAGEVIEW上显示图像后,我想将该图像保存在应用程序中以在不同的View Controller上显示同一图像。
您可以将图像放在全局变量中。全局变量可以在所有应用程序中使用。 :
var imageSelected:UIImage? // Value will be nil if no image has been set
class ViewController1 {
// Puts your image inside a global variable
image = yourImage
}
class ViewController2 {
// Uses the image that was defined inside the global variable
@IBOutlet weak var imageView: UIView!
imageView.image = imageSelected
}