KEVIN
KEVIN

Reputation: 163

Hide keyboard on button press IOS

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

Upvotes: 2

Views: 805

Answers (3)

Nagarajan Sathish
Nagarajan Sathish

Reputation: 137

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

Upvotes: 0

Raghavandra Santosh
Raghavandra Santosh

Reputation: 181

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

Upvotes: 1

jherran
jherran

Reputation: 3367

[self.textfield resignFirstResponder];

- resignFirstResponder

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

Upvotes: 2

Related Questions