ins*_*ing 5 uibutton uiview isenabled swift
我在这里找到的解决方案使用的.enabled是旧的,而不是.isEnabled.
因此,如果满足(或不满足)某个条件,我正在尝试仅禁用按钮的功能/可点击性。所以在这一切之前,如果不满足条件,我将它们全部禁用,然后如果在(动态)之后满足它,那么理论上应该启用。话虽如此,当我从.isEnabled = false.
我知道满足条件是因为我有打印语句和其他测试(比如标签从超级视图中删除但.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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
真的吗?它应该工作。
1.) 这就是我如何禁用按钮并且它正在工作。
myButton.isEnabled = false;
Run Code Online (Sandbox Code Playgroud)
2.)通过禁用用户交互来禁用按钮的绝望方法。
myButton.isUserInteractionEnabled = false;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5195 次 |
| 最近记录: |