How do I add a IBAction to a button programmatically?
button.addTarget(self, action: Selector(("buttonAction:")), for:
.touchUpInside)
func buttonAction(sender: Any) {
print("test")
}
That gives me an "Thread 1: signal SIGABRT" error.
Swift 4 version:
button.addTarget(self, action: #selector(action(sender:)), for: .touchUpInside)
@objc private func action(sender: Button) {
print("test")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With