参见英文答案 Instance member cannot be used on type of custom class3个 我正在通过stanford课程在线讲座来制作专注游戏,我的代码的一部分出现错误.我收到错误“实例成员’cardButtons’不能用于类型
我正在通过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 = ["