当我将按钮放置在数组中时,无法设置背景和isSelected属性

时间:2019-06-21 19:23:13

标签: xcode uibutton

我试图一次更改按钮的所有属性,但出现错误。当我执行button2.isSelected = false时,它可以工作,但是当我在for循环中执行时,得到Value of type '(ViewController) -> (UIButton) -> ()' has no member 'isSelected'

这是我的代码:

var buttonsArray = [FirstButton,button2,button3,button4,button5,button6,button7,button8,button9,button10,button11,button12,button13,button14,button15,button16,button17,button18,button19,button20,button21]

@IBOutlet weak var button2: UIButton!
@IBAction func button2(_ sender: UIButton) {

    if button2.isSelected == false{
        button2.isSelected = true
        button2.backgroundColor = UIColor.red
        if startPick == true && endPick == true{
            for item in buttonsArray{
                item.isSelected = false
            }
             button2.isSelected = true
            startPick = true
            endPick = false
        }
        else if startPick == false && endPick == false{
            endPick = false
            startPick = true
        }
        else if startPick == true && endPick == false{
            endPick = true
        }
        checkSwitches()

    }
    else
    {
        button2.isSelected = false
        button2.backgroundColor = UIColor.orange
        checkSwitches()
    }



}

for循环是我得到错误的地方。 编辑:我是xcode的新手。当我尝试通过数组调用按钮时,是否存在引用问题?

0 个答案:

没有答案