Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subclass a UITextField and detect when it becomes or resigns first responder

I subclassed a UITextField and wish to get a method called when it becomes first responder or resigns first responder. How can I achieve this?

like image 400
Ben Lu Avatar asked Dec 12 '22 02:12

Ben Lu


1 Answers

Just override becomeFirstResponder to call your method. Something like,

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

See the docs here for more info on responder methods: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/cl/UIResponder

like image 194
Matt Avatar answered Dec 15 '22 01:12

Matt