Subclass a UITextField and detects when it becomes or retires the first responder

I have subclassed UITextField and would like to get a method called when it becomes the first responder or resigns from the first responder. How can I achieve this?

+3
source share
2 answers

Just override startFirstResponder to call your method. Sort of,

    - (BOOL)becomeFirstResponder
    {
        BOOL returnValue = [super becomeFirstResponder];
        if (returnValue) {
            [self method];
        }
        return returnValue;
    }

For more information on response methods, see the docs: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/cl/UIResponder

+12
source

. :

- (void)textFieldDidBeginEditing:(UITextField *)textField{
     //call some custom code here...
}
+1

All Articles