加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:10:18 所属栏目:百科 来源:网络整理
导读:参见英文答案 Instance member cannot be used on type of custom class????????????????????????????????????3个 我正在通过stanford课程在线讲座来制作专注游戏,我的代码的一部分出现错误.我收到错误“实例成员’cardButtons’不能用于类型’ViewControlle
参见英文答案 > 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 = ["                        

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读