【发布时间】:2017-05-21 14:04:30
【问题描述】:
我在 Swift 3 中子类化了一个用 Objective-C 编写的 UIButton 子类。
当我尝试添加目标时,它会失败并显示错误代码:
class ActionButton: JTImageButton {
func action() {
}
func configure()) {
// ...
self.addTarget(self, action: #selector(self.action()), for: .touchUpInside)
// error:
// Argument of '#selector' does not refer to an '@objc' method, property, or initializer
}
}
【问题讨论】:
-
你的
action方法与UIView的action(for:, forKey:)方法冲突,比较stackoverflow.com/questions/35658334/…。
标签: ios objective-c swift cocoa-touch