ios – 错误:实例成员不能用于’ViewController’类型[复制]

前端之家收集整理的这篇文章主要介绍了ios – 错误:实例成员不能用于’ViewController’类型[复制]前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Instance member cannot be used on type of custom class                                    3个
我正在通过stanford课程在线讲座来制作专注游戏,我的代码的一部分出现错误.我收到错误“实例成员’cardButtons’不能用于类型’ViewController’”,但代码似乎适用于教师.有人可以帮我解决这个问题吗?这是代码的一部分.第4行出错

import UIKit

class ViewController: UIViewController {

@IBOutlet var cardButtons: [UIButton]!

lazy var game = Concentration(numberOfPairsOfCards: cardButtons.count / 2)

var flipCount = 0 {
    didSet {
        flipCountLabel.text = "Flips: \(flipCount)"
    }
}

@IBOutlet weak var flipCountLabel: UILabel!


@IBAction func touchCard(sender: UIButton) {
    flipCount += 1
    if let cardNumber = cardButtons.indexOf(sender) {
        game.chooseCard(at: cardNumber)
        updateViewFromModel()
    } else {
        print("chosen card was not in array cardButtons")
    }

}

func updateViewFromModel() {
    for index in cardButtons.indices {
        let button = cardButtons[index]
        let card = game.cards[index]
        if card.isFaceUp {
            button.setTitle(emoji,forState: UIControlState.Normal)
            button.backgroundColor = UIColor.whiteColor()
        } else {
            button.setTitle("",forState: UIControlState.Normal)
            button.backgroundColor = card.isMatched ? UIColor.clearColor() : UIColor.orangeColor()
        }

    }
}

    var emojiChoices = ["

猜你在找的Xcode相关文章