按下按钮时如何从按钮数组中禁用其余按钮 [英] How disable rest of the buttons from an array of buttons when button is pressed

查看:77
本文介绍了按下按钮时如何从按钮数组中禁用其余按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在快速代码中禁用方法.dis遇到麻烦.我有一个按钮数组,我想在按下正确的按钮(目标按钮)时禁用其余按钮.我的数组是呼叫按钮!这是按钮的操作.我必须在按钮中使用不同的名称吗?或者我可以使用.count方法?谢谢,感谢一切.

Im having some trouble with method .disable in swift code. I have an array of Buttons and I want to disable the rest of Buttons when the correct Button (Target Button) is pressed. My array is call Buttons! Here are the action for the Buttons. I have to have different names in the Buttons? or I can use .count method? Thank you and appreciate everything.

@IBAction func btn1(sender: AnyObject) {
    if answerNumber == 0 {
        cwLabel.text = "You are Right!"
        pickQuestion()
        Buttons.count

    } else {
        cwLabel.text = "You are Wrong!"
        pickQuestion()
    }
}

@IBAction func btn2(sender: AnyObject) {
    if answerNumber == 1 {
        cwLabel.text = "You are Right!"
        pickQuestion()

    } else {
        cwLabel.text = "You are Wrong!"
        pickQuestion()
    }
}

@IBAction func btn3(sender: AnyObject) {
    if answerNumber == 2 {
        cwLabel.text = "You are Right!"
        pickQuestion()

    } else {
        cwLabel.text = "You are Wrong!"
        pickQuestion()
    }
}

@IBAction func btn4(sender: AnyObject) {
    if answerNumber == 3 {
        cwLabel.text = "You are Right!"
        pickQuestion()

    } else {
        cwLabel.text = "You are Wrong!"
        pickQuestion()
    }
}

推荐答案

您是要禁用所有按钮还是禁用所有按钮?您可以使用切换

Do you mean to disable all of buttons or upressed ones? You can use toggle

func toggleButtons(button: UIButton) {
    for (var index = 0; index < arrayButton.count; index += 1) {
        if arrayButton[index] != button {
            arrayButton[index].enabled = false
        }
    }
}

这篇关于按下按钮时如何从按钮数组中禁用其余按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆