不能称之为非功能类型的UIImage?'

时间:2015-11-28 21:37:36

标签: ios uiimage swift2.1

我正在尝试运行此代码,将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。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:3)

要设置现有UIImageView的属性UIImage,您需要为其分配PersonsChoice.image = UIImage(named: option[randomNumber]) 的新实例:

text

UILabel的{​​{1}}:

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