使用Swift #selector()引用目标/操作中的协议方法的编译器错误

时间:2017-03-06 14:32:07

标签: swift events protocols target uicontrol

我有一个自定义UIControl,并希望为特定的UIControlEvents添加目标。所以我在自定义UIControl中指定了一个协议和一个委托变量:

protocol FieldEventHandlerDelegate {
    func willSelectField(sender:Field)
}

class Field {
    var delegate:FieldEventHandlerDelegate?

    func setupEventHandlers(withDelegate del:FieldEventHandlerDelegate) {
        delegate = del
        self.addTarget(delegate, action: #selector(willSelectField(sender:)), for: .touchUpInside)
}

但是Xcode给了我错误:Use of unresolved identifier 'willSelectField(sender:)'

0 个答案:

没有答案