2

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

E-Riddie
  • 14,660
  • 7
  • 52
  • 74
KEVIN
  • 155
  • 2
  • 13
  • 3
    resignFirstResponder is the way to go here. Use it like: `[YourTextfield resignFirstResponder];` – Widerberg Nov 17 '14 at 09:50
  • what is the first responder of keyboard? – Toseef Khilji Nov 17 '14 at 09:50
  • It's the object that you tap to bring up the keyboard such as, textfields and textviews. Find out which object you are tapping that brings up the keyboard and when you call showDateView you use [someTextField resignFirstResponder] to dismiss the keyboard as suggested by Alexander. – Kiran Thapa Nov 17 '14 at 09:59
  • possible duplicate of [How to hide the keyboard when touching screen (search bar)](http://stackoverflow.com/questions/16956566/how-to-hide-the-keyboard-when-touching-screen-search-bar) – orkenstein Nov 17 '14 at 10:09

3 Answers3

2
[self.textfield resignFirstResponder];

- resignFirstResponder

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

jherran
  • 3,337
  • 8
  • 37
  • 54
1

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

0
[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.