簡體   English   中英

不能調用非函數類型'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!"

暫無
暫無

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM