无法调用非函数类型的值 'UIImage?'
Cannot call value of non-function type 'UIImage?'
我正在尝试 运行 此代码将随机化一个 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])
对于 UILabel
的 text
同样的事情:
resultLabel.text = "It's a draw!"
我正在尝试 运行 此代码将随机化一个 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])
对于 UILabel
的 text
同样的事情:
resultLabel.text = "It's a draw!"