我正在尝试将已缓存/已下载的图像传递到我的显示视图控制器,该图像将与其他图像相隔离。我可以下载图像并将其设置为当前控制器上的UIImageView,或者如果我手动下载UIImage图像,则可以在将其分配给ImageStore变量时选择它。但是,当通过缓存/下载方法下载图像时,它以UIImageView的形式出现,如何将其作为变量传递给另一个控制器?
@IBOutlet weak var Image1: UIImageView!
var ImageStore: UIImage!//transfer image code to next screen
var ImageStore: UIImage!//transfer image code to next screen
@IBAction func Chart1Click(_ sender: Any)//chart 1
{
performSegue(withIdentifier: "Chart1", sender: nil)
}
@IBAction func Chart2Click(_ sender: Any)//chart 2
{
performSegue(withIdentifier: "Chart2", sender: nil)
}
@IBAction func Button(_ sender: Any)//download charts
{
Image1.sd_setImage(with: URL(string: "https://www.vedur.is/photos/flugkort/PGDE14_EGRR_0000.png"), placeholderImage: UIImage(named: "placeholder.png"))
//assing the Image1 to ImageStore ??
//more downloaded here
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
if (segue.identifier == "Chart1")
{
let destinationViewController = segue.destination as! ChartAController
destinationViewController.TransferImage = ImageStore
print("Chart 1 Segue")
}
if (segue.identifier == "Chart2")
{
let destinationViewController = segue.destination as! ChartAController
destinationViewController.TransferImage = ImageStore2
print("Chart 2 Segue")
}
}
仅发送
ImageStore.image
它应该解决问题。如果要发送图像而不是imageView。