[英]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!"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.