gpt4 book ai didi

ios - 无法调用非函数类型的值 'UIImage?'

转载 作者:可可西里 更新时间:2023-11-01 05:43:26 24 4
gpt4 key购买 nike

我正在尝试运行这段代码,它会随机生成一个 UIImage。但我收到以下错误 Cannot call value of non-function type 'UIImage?

@IBOutlet weak var resultLabel: UILabel!
@IBOutlet weak var PersonsChoice: UIImageView!
var option = ["rock.png", "paper.png", "scissors.png"]

func chooseWinner(userChoice:Int){
let randomNumber = Int(arc4random_uniform(3))
PersonsChoice.image(option[randomNumber])

if (randomNumber == 0 && userChoice == 1)
|| (randomNumber == 1 && userChoice == 2)
|| (randomNumber == 2 && userChoice == 0) {
resultLabel.text("You Win")
} else if (userChoice == 0 && randomNumber == 1)
|| (userChoice == 1 && randomNumber == 2)
|| (userChoice == 2 && randomNumber == 0) {
resultLabel.text("I Win!")
} else {
resultLabel.text("It's a draw!")
}
}

我也收到错误 Cannot call value of non-function type 'String?'对于 resultLabel.text。任何帮助将不胜感激。

最佳答案

要设置现有 UIImageView 的属性 image,您需要为其分配一个新的 UIImage 实例:

PersonsChoice.image = UIImage(named: option[randomNumber])

对于 UILabeltext 也是一样:

resultLabel.text = "It's a draw!"

关于ios - 无法调用非函数类型的值 'UIImage?',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33976722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com