I have a
UITextField subclass. I needed to know when text did change and I was able to get that with
NotificationCenter and observing
.UITextFieldTextDidChange but now I need to know when the user tap return button. The only solution that I can think about it is setting the
UITextField subclass to be the delegate of it self, but it sound not clean.
UITextField subclass to be the delegate of it self ?
In your subclass do
self.addTarget(self, action: #selector(returnKeyPressed), for: .editingDidEndOnExit);
Looking at Apples doc you see UIControlEvents
UIControlEventEditingDidEndOnExit = 1 << 19, // 'return key' ending editing