Skip to content

Instantly share code, notes, and snippets.

@owenzhao
Last active January 15, 2017 12:56
Show Gist options
  • Save owenzhao/0030dac0498572b7d2bf8da637925bbd to your computer and use it in GitHub Desktop.
Save owenzhao/0030dac0498572b7d2bf8da637925bbd to your computer and use it in GitHub Desktop.
notification
@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