1

How can I override the addTarget function inside the UITextField class, but only for UIControlEvent.allEditingEvents?

The function is like this, however I am not sure how to apply it only for a specific control event.

override func addTarget(_ target: Any?, action: Selector, for controlEvents: UIControlEvents) {
    <#code#>
}
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
dre_84w934
  • 678
  • 8
  • 27

1 Answers1

3

You should call super.addTarget and only call your custom code if controlEvents equals to .allEditingEvents.

override func addTarget(_ target: Any?, action: Selector, for controlEvents: UIControlEvents) {
    super.addTarget(target, action: action, for: controlEvents)

    if controlEvents == .allEditingEvents {
        [your code]
    }
}
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223