PDA

View Full Version : Question: Hiding the keyboard when a UITextField is empty




arubinst
Oct 10, 2008, 12:09 PM
Hi,

I've googled around for this problem but I find nothing. I'm wondering if I'm the only one...

I have setup a view with 2 TextFields in IB. Delegates of the TextFields are correctly set and the ViewController implements the UITextFieldDelegate protocol.

I would like to dismiss the keyboard with the "Done" key, but the key is grayed out while the TextField is empty. Once I type any character, the Done key is enabled and I can dismiss the keyboard with:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@"textFieldShouldReturn");
[textField resignFirstResponder];
return YES;
}

So, what am I missing? Why is the "Done" key disabled when the TextField is empty?

By the way, I looked at the UICatalog sample program and couldn't figure out how they handle the keyboard hiding.

Another question: How do I dismiss a "Phone Pad" or "Number Pad" keyboard? The textFieldShouldReturn is ignored since there is no Return or Done key. I can set a "Save" or "Cancel" button somewhere in the navigation bar but I really don't know what those buttons need to do in order to hide this keyboard.

Thanks in advance,

Arubinst



jerdiver
Oct 10, 2008, 07:05 PM
Hi,

I'm very new to XCode but have you tried to uncheck the "Auto-enable Return Key" text field attribute in Interface Builder ?

PhoneyDeveloper
Oct 10, 2008, 07:19 PM
Look at UITextInputTraits.

resignFirstResponder will hide the keyboard.

arubinst
Oct 11, 2008, 02:13 AM
Hi,

I'm very new to XCode but have you tried to uncheck the "Auto-enable Return Key" text field attribute in Interface Builder ?That did it! Thanks!

mozmac
Oct 24, 2008, 02:16 PM
I'm still wondering the answer to the second question. How do you hide the number pad keyboard? Is there a way to add a "Done" button to the bottom left key on the pad, since it is an empty spot?