Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift3 禁用多个按钮_Swift3 - Fatal编程技术网

Swift3 禁用多个按钮

Swift3 禁用多个按钮,swift3,Swift3,我正在学习swift3,并决定尝试一个Tictatcoe游戏。我试图在游戏结束后禁用所有按钮。我试着去做 sender.isEnabled = false 但这给了我一个错误。除了为单个按钮制作插座并逐个禁用按钮外,是否有其他方法禁用所有按钮? 下面是我的代码 @IBAction func button(_ sender: AnyObject) { let gamePosition = sender.tag - 1 if gamePlay == true {

我正在学习swift3,并决定尝试一个Tictatcoe游戏。我试图在游戏结束后禁用所有按钮。我试着去做

sender.isEnabled = false
但这给了我一个错误。除了为单个按钮制作插座并逐个禁用按钮外,是否有其他方法禁用所有按钮? 下面是我的代码

@IBAction func button(_ sender: AnyObject) {
    let gamePosition = sender.tag - 1

    if gamePlay == true {

        if gameState[gamePosition] == 0 {

            if activePlayer == 1 {

                sender.setImage(UIImage(named: "nought.png"), for: [])

                gameState[gamePosition] = activePlayer

                activePlayer = 2


            } else {

                sender.setImage(UIImage(named: "cross.png"), for: [])

                gameState[gamePosition] = activePlayer

                activePlayer = 1

            }

        }

    }


    for combination in winningCombination {

        if gameState[combination[0]] != 0 && gameState[combination[0]] == gameState[combination[1]] && gameState[combination[1]] == gameState[combination[2]] {

            gamePlay = false

            resultLabel.isHidden = false
            playAgainButton.isHidden = false

            if gameState[combination[0]] == 1 {

                resultLabel.text = ("noughts have won")

            } else {

                resultLabel.text = (" crosses won")

            }
出于某种原因(我假设有一个bug),拖动
UIButton
操作将
AnyObject
而不是
UIButton
默认设置为发送方类型

替换:

@IBAction func button(_ sender: AnyObject) {
与:


AnyObject
更改为
UIButton
修复了我得到的错误。 为了在游戏结束后禁用所有按钮,我这样做了(不确定这是否是最好的方法)


对于1中的i.。错误是什么?错误是“无法分配到属性:'sender'是一个'let'constantI无法使用
sender.isEnabled=false
复制此内容。请(仅)在使用
sender.isEnabled=false
的位置发布相关代码。
@IBAction func button(_ sender: UIButton) {
for i in 1..<10 {
    if let Button = view.viewWithTag(i) as? UIButton{
        Button.isEnabled = false
        }