【问题标题】:Cannot assign value of type 'UIImage' to type 'UIImageView'无法将“UIImage”类型的值分配给“UIImageView”类型
【发布时间】:2020-07-29 10:35:47
【问题描述】:

我正在做一个简单的个性测验,根据结果它将在我的主故事板上的 ImageView 中显示某个图像。在 QuestionData.Swift 中,我使用了以下 switch 语句:

var image: UIImage { //personality image
   switch self { //Checking what answer it matches to
   case .open: return UIImage(named: "football.jpg")!
   case .conscience: return UIImage(named: "football.jpg")!
   case .extra: return UIImage(named: "football.jpg")!
   case .agree: return UIImage(named: "football.jpg")!
   case .neuro: return UIImage(named: "football.png")! //for testing purposes all images are the same
    }

}

在我的 ResultsViewController 中:

 @IBOutlet weak var resultsImage: UIImageView!

//function code goes here

            resultsImage = mostCommonAnswer.image //matches image to personality result

我收到错误“无法将 'UIImage' 类型的值分配给类型 'UIImageView'”

任何想法如何解决这个问题?

【问题讨论】:

    标签: swift xcode uiimageview switch-statement uiimage


    【解决方案1】:

    您需要将图像设置为UIImageViewUIImage 属性

    resultsImage.image = mostCommonAnswer.image
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-02
      • 2022-08-18
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多