如何覆盖addTarget
课程中的UITextField
功能,但仅适用于UIControlEvent.allEditingEvents
?
函数是这样的,但是我不知道如何仅将它应用于特定的控件事件。
override func addTarget(_ target: Any?, action: Selector, for controlEvents: UIControlEvents) {
<#code#>
}
答案 0 :(得分:2)
如果super.addTarget
等于controlEvents
,您应致电.allEditingEvents
并仅调用自定义代码。
override func addTarget(_ target: Any?, action: Selector, for controlEvents: UIControlEvents) {
super.addTarget(target, action: action, for: controlEvents)
if controlEvents == .allEditingEvents {
[your code]
}
}