我正在尝试运行此代码,将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
。任何帮助将不胜感激。
答案 0 :(得分:3)
要设置现有UIImageView
的属性UIImage
,您需要为其分配PersonsChoice.image = UIImage(named: option[randomNumber])
的新实例:
text
UILabel
的{{1}}:
resultLabel.text = "It's a draw!"