Reputation: 169
I am working on an app, which has UISwitch. I want to set the switch to on/off programmatically. I tried it like so, but the switch is already turned on when setting
is false
... Any ideas?
@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)
}
}
the variable setting
is not the problem.. I tested it out
Upvotes: 5
Views: 11867
Reputation: 169
I fixed it!
I just deleted the line switch = UISwitch()
and now it works for me.
Upvotes: 3