Swift 在尝试打开UIImage时意外发现nil

Swift 在尝试打开UIImage时意外发现nil,swift,Swift,由于某种原因,当我尝试初始化一个映像时,我得到了零。 图像保存在“资源”文件夹中,且名称正确。什么会导致它为零 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == Storyboard.groupDetailsVC { if let vc = segue.destination as? GroupDetailsViewController {

由于某种原因,当我尝试初始化一个映像时,我得到了零。 图像保存在“资源”文件夹中,且名称正确。什么会导致它为零

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == Storyboard.groupDetailsVC {
        if let vc = segue.destination as? GroupDetailsViewController {

            vc.groupImageView.image =  UIImage(named: "icon-checkbox")
            //it outputs error 

        }
    }

}

问题不在图像中,而是在Vc加载之前访问imageView

vc.groupImageView.image =  UIImage(named: "icon-checkbox")
//

//


问题不在图像中,而是在Vc加载之前访问imageView

vc.groupImageView.image =  UIImage(named: "icon-checkbox")
//

//


如果要将图像传递给GroupDetailsViewController,只需传递图像而不传递。不要尝试在prepareSegu中设置图像。将图像设置到GroupDetailsViewController viewDidLoad中,而不是在PrepareForegue中。问题是您的groupImageView出口仍然未连接,因为此时未调用CV的loadview。你必须在你的VC中创建一个UIImage变量,并可以将其分配给你正在创建的图像。我明白。我应该意识到这一点。如果您想将图像传递给GroupDetailsViewController,只需传递图像,而不传递图像。不要尝试在prepareSegu中设置图像。将图像设置到GroupDetailsViewController viewDidLoad中,而不是在PrepareForegue中。问题是您的groupImageView出口仍然未连接,因为此时未调用CV的loadview。你必须在你的VC中创建一个UIImage变量,并可以将其分配给你正在创建的图像。我明白。我应该意识到这一点。
class GroupDetailsViewController:UIViewController {
  @IBOutlet weak var groupImageView: UIImageView!
  var sendedImage:UIImage!
  override func viewDidLoad() {
    super.viewDidLoad()
    self.groupImageView = sendedImage

  }
}