我在这里找到的解决方案使用的是.enabled,它是旧的,而不是.isEnabled. 所以我正在尝试在某个条件满足(或不满足)的情况下禁用按钮的功能/可点击性.所以在它之前,如果条件不满足则禁用所
所以我正在尝试在某个条件满足(或不满足)的情况下禁用按钮的功能/可点击性.所以在它之前,如果条件不满足则禁用所有条件,然后如果在(动态)它满足之后,它理论上应该启用.话虽这么说,当我开始使用.isEnabled = false时,它最初不会禁用按钮.
我知道这个条件正在得到满足,因为我有打印语句和其他测试(比如标签被删除了fromuperview还是.isEnabled = false因为按钮不起作用.有人遇到过这些问题或有任何解决方案吗?
代码如下:
override func viewDidLoad() { super.viewDidLoad() trumpMoneyDefault.setValue(50, forKey: "TrumpMoney") print("UnoViewController") //make all the buttons that shouldn't be clickable unlcickable locklvl2.isEnabled = false locklvl3.isEnabled = false trumplvl2.isEnabled = false trumplvl3.isEnabled = false lvl2.isEnabled = false lvl3.isEnabled = false //make level2/3 unclickable by defeault //lvl2.isEnabled = false //lvl3.isEnabled = false //update trumpmoney label depending on if they have enough cash //also here check if they have already unlocked all via purchase of unlock all. If so, then skip all this if trumpMoneyDefault.value(forKey: "TrumpMoney") != nil { trumpmoney.text = trumpMoneyDefault.value(forKey: "TrumpMoney") as? String //remove locks if they got the money by default. let tempTrumpMoneyDefault = trumpMoneyDefault.value(forKey: "TrumpMoney") as! Int if tempTrumpMoneyDefault >= 100 { locklvl2.removeFromSuperview() moneylvl2.removeFromSuperview() trumplvl2.removeFromSuperview() lvl2.isEnabled = true if tempTrumpMoneyDefault >= 500 { locklvl3.removeFromSuperview() moneylvl3.removeFromSuperview() trumplvl3.removeFromSuperview() lvl3.isEnabled = true } } } }真?它应该工作.
1.)这是我禁用按钮的方式,它正在工作.
myButton.isEnabled = false;
2.)通过禁用用户交互来禁用按钮的绝望方式.
myButton.isUserInteractionEnabled = false;