Take the 2-minute tour ×

I am trying to hide the keyboard in my SplitView application (because it covers over part of the root menu). However, the only thing I can find is how to hide the keyboard after a textfield has been used [TextField resignFirstResponder].

Is there any other way to hide the keyboard?
Ideally I would like to use the barButtonItem, which displays the menu, as a trigger to hide the keyboard.

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

Use this:

[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
share|improve this answer
exactly what I was looking for, works perfectly ! –  BloonsTowerDefence Aug 15 '12 at 18:15
add comment

You need to send the -resignFirstResponder message to the instance of whatever UI element currently has first responder status. So if there were a firstNameTextField property on your class that corresponds to an instance of UITextField, you need to send the message to that object.

[self.firstNameTextField resignFirstResponder];

share|improve this answer
Does it work with any UI element? Can I use a UIBarButtonItem? My whole problem is that I don't have a specific textfield to link it to. –  BloonsTowerDefence Aug 15 '12 at 17:46
Technically any instance of UIView can become the first responder since it is a subclass of UIResponder but it only invokes the keyboard if the class conforms to the UITextInput protocol. To dismiss the keyboard via a UIBarButtonItem, you need to connect that button to a method that invokes resignFirstResponder on the active text field. If you just want to blindly end all editing, you can also send endEditing: to the root view and it will walk through the subviews and resign first responder on which ever subview currently has it. –  Mark Adams Aug 15 '12 at 17:50
add comment

resignFirstResponder is way to do it. If you have a situation where your firstResponder is not set up as an instance variable (perhaps its generated), you can 'get' your firstResponder using this answer. After you have your first responder object, simply resign it!

hope this helps.

share|improve this answer
add comment

Your Answer


