我正在向按钮添加操作
let button = UIButton()
button.addTarget(self, action: #selector(touchButton(button)), for: .touchUpInside)
而且我有@objc方法
@objc public func touchButton(_ sender: UIButton) {
let soundNumber = soundButtons.index(of: sender)! //The index of the button
...
}
我为什么还收到
Argument of '#selector' does not refer to an '@objc' method, property, or initializer
您使用的签名与objc方法不匹配。正确的选择器应该是touchButton(_:)
,而不是touchButton(button)
。