swift - 按钮操作的代码是什么?

标签 swift cosmicmind

我又来了,我很喜欢这个库,但有时会遇到一些小问题。

对于RaishedButton,以编程方式创建按钮时需要什么代码来创建操作?

btn1.addTarget(self, action: "okButton", forControlEvents: UIControlEvents.TouchUpInside)

func okButton(sender:RaisedButton!) {
    print("button pressed")
}

导致发送到实例的选择器无法识别

最佳答案

在您的代码中删除可选参数的展开:

func okButton(sender: RaisedButton) {
    print("button pressed")
}

在选择器名称末尾添加“:”:

btn1.addTarget(self, action: "okButton:", forControlEvents: .TouchUpInside)

这应该可以解决您的问题:)

关于swift - 按钮操作的代码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35375493/

相关文章:

ios - 当协议(protocol)的可空性发生变化时支持多个 iOS SDK 版本

swift - 在后台点击 Swift 时禁用关闭弹出框

swift - AWS APIGateway 和 Lambda - 如何在 iOS 应用程序终止之前立即调用函数?

ios - NavigationController nil with Material

ios - 从 CosmicMind-Material 捕获 API : Camera preview not correct

ios - CosmicMind/图表 : Search for Specific Related Entities

ios - setValueForKeys 失败了 Swift

ios - 在 CreateML 中重新导入 mlmodel

ios - Comicmind Material Framework 按钮事件处理程序