Csabi Csabi - 1 year ago 140
iOS Question

how to hide keyboard in UIViewController on return button click->iphone

Hi I find some questions like that but they talk about textView, I have ViewController, with scrollView where are 6 textfield and one textView I want a function which makes the keyboard disappear on on done/return button click.I implemented functions resign to first responder, which hide my keyboard when i click outside of scrollView, but that is not exactly i want, because i like to make it disappear on button click too.

THanks for any help

Answer Source

Set up a class that conforms to the UITextFieldDelegate protocol and make the delegate of your text fields an instance of this class. Implement the method:

- (BOOL)textFieldShouldReturn:(UITextField *)textField

As follows:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download