get notified when UITextField becomeFirstResponder
Solution 1
You will need to be come the text field's delegate and implement this optional delegate method:
- (void)textFieldDidBeginEditing:(UITextField *)textField;
Solution 2
Besides implementing the UITextFieldDelegate
method textFieldDidBeginEditing:
, you can register for the UITextFieldTextDidBeginEditingNotification
notification.
The notification method could be:
- (void)someTextFieldDidBeginEditing:(NSNotification *)notification {
UITextField *textField = (UITextField *)notification.object;
}
Solution 3
The delegate is definitely the way to go. Unfortunately, in my situation I couldn't use that, because the controller was the delegate of my UITextField subclass and I needed to modify it's placeholder text. Instead I override the methods - (BOOL)canBecomeFirstResponder;
& - (BOOL)resignFirstResponder;
. Be sure to call super.
shebelaw
Updated on March 02, 2020Comments
-
shebelaw over 4 years
How I can get notified when
UITextField
becomeFirstResponder
?I can check like
isFirstResponder
or set to to become first Responder bybecomeFirstResponder
I want to get notified or handle an event when a user make this text field first responder.
Thanks.