Last active
January 15, 2017 12:56
-
-
Save owenzhao/0030dac0498572b7d2bf8da637925bbd to your computer and use it in GitHub Desktop.
notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func printHello(_ sender: Any) { | |
// 消息绑定 | |
if shouldWaitSwitch.isOn { | |
if let _ = shouldWaitSwitch.actions(forTarget: self, forControlEvent: .valueChanged) { // already set | |
return | |
} | |
shouldWaitSwitch.addTarget(self, action: #selector(printHello(_:)), for: .valueChanged) | |
} | |
else { | |
print("你好!") | |
if let _ = shouldWaitSwitch.actions(forTarget: self, forControlEvent: .valueChanged) { // if set | |
shouldWaitSwitch.removeTarget(self, action: #selector(printHello(_:)), for: .valueChanged) | |
} | |
} | |
} | |
@IBOutlet weak var shouldWaitSwitch: UISwitch! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment