I have a switch thats prints "its on" when its on and "its off" when its off. Since i want to have more switches in future, i decided i wanted to have a button that acts as a general, therefore when i press the button, the switch sets itself on, but the problem is, it doesn't print "its on".
Essentially if i directly click the switch, it does what its supposed to; if i change the switch's status through the button, it doesn't, it only switches on, and doesn't print anything.
BUTTON CODE:
@IBAction func Button(sender: UIButton) {
self.SSwitch.setOn(true, animated: false)
}
SWITCH CODE:
@IBAction func Switch(sender: UISwitch) {
if self.SSwitch.on {
print("its on")
}
else {
print("its off")
}
This is the expected situation.
If a user triggers a change then the control will send action messages to each of its targets. If the change was made directly in code however no action messages will be sent.
So, if you change the state in code it's up to you to send the (appropriate) action messages if it makes sense to do so.