BloonsTowerDefence
BloonsTowerDefence

Reputation: 1204

Hiding the UIKeyboard

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.

Upvotes: 7

Views: 3329

Answers (3)

Steven Fisher
Steven Fisher

Reputation: 44876

Use this:

[[[UIApplication sharedApplication] keyWindow] endEditing:YES];

Upvotes: 13

KDaker
KDaker

Reputation: 5909

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.

Upvotes: 0

Mark Adams
Mark Adams

Reputation: 30846

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];

Upvotes: 0

Related Questions