问题描述:

I need to hide the IOS keyboard when i press a button on the screen.

Whatever i try, the keyboard doesn't go away when i press the button on the screen.

// This is the button

-(IBAction)showDateView:(id)sender

// hide keyboard

[self.view endEditing:YES];

}

Thanks

网友答案:
[self.textfield resignFirstResponder];

- resignFirstResponder

Notifies the receiver that it has been asked to relinquish its status as first responder in its window.

网友答案:

in general there may be more than one textfields in your screen you don't know which textField must be resigned so add all the textField objects into an array and iterate a loop to resignFirstResponder

for (uilabel *textField in labelObjArray) {

    [textField/textView resignFirstResponder]
}

the key board will be resigned immediate

网友答案:
[self.view endEditing:YES];

This will work if the responder was initiated from the view.

[self.navigationController.navigationBar endEditing:YES]

This will work if the responder was initiated from the navigation bar.

相关阅读:
Top