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")
}
@objc annotation@objc func action(sender: Button)
IBActionprogrammatically - the "IB" stands for "Interface Builder". What you mean to ask is how use thesenderin anaddTarget(action:)call.