[英]How do I add a IBAction to a button programmatically in Swift 4?
如何以编程方式将 IBAction 添加到按钮?
button.addTarget(self, action: Selector(("buttonAction:")), for:
.touchUpInside)
func buttonAction(sender: Any) {
print("test")
}
这给了我一个“线程 1:信号 SIGABRT ”错误。
斯威夫特 4 版本:
button.addTarget(self, action: #selector(action(sender:)), for: .touchUpInside)
@objc private func action(sender: Button) {
print("test")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.