UISwitch设置状态
问题描述:
我正在开发一个具有UISwitch的应用程序。我想以编程方式将开关设置为打开/关闭。我试过这样,但开关已经打开时,setting
是false
...任何想法?UISwitch设置状态
@IBOutlet var switch: UISwitch!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
switch = UISwitch()
if setting == true {
switch.setOn(true, animated: false)
} else {
switch.setOn(false, animated: false)
}
}
变量setting
是没问题的。我测试了它
答
我定了!
我刚刚删除了行switch = UISwitch()
,现在它适用于我。
从您发布的代码中,如果'setting'为'false',那么开关将关闭。这不是预期的功能吗? – random
你能指定更多细节吗? – barryjones
关于您期望的功能和实际功能的更多细节将对我们有很大帮助。 – ZGski