Search code examples
objective-cibaction

Keyboard resignfirstresponder when Click Done


I have a textfield called searchBox and am trying to get rid of the keyboard if the user either clicks on Done.

Is there an IBAction that I need to know to do this?


Solution

  • You have to make your viewcontroller an UITextFieldDelegate and write in

    viewDidLoad:
    [searchBox setDelegate:self];
    

    And then write:

    - (BOOL)textFieldShouldReturn:(UITextField *)textfield
    {
        [searchbox resignFirstResponter];
        return YES;
    }