Assuming you have the delegate set, and have this in your interface's protocol list "<UITextFieldDelegate>," having your text field resign the first responder should automatically make the keyboard hide. If it doesn't, then you have a delegation issue.
EDIT: Make sure that your button that you are using to dismiss the number pad tells has something like this:
[yourTextField resignFirstResponder];
It works fine with the alpha keyboard, not the number pad though. Because (I assume) the alpha keyboard has "done" in it - then the resignFirstResponder stuff works fine. With a Number Pad, there's no done key, so never any option to call the resignFirstResponder stuff.
I would like to see your code. I have done this, and I assure it works (You can download my app on the AppStore, search Skylar Cantu to see this in action. I don't want to give you a link, or the name because I don't want to SPAM).
Can you post your code here, or would that ruin the secrecy of your app? I don't need to see all the code, just the interface declaration of the object that contains the textfield, and any code relevant to the text field.
The delegate for the TextField is File's Owner of the ViewController, in which the code above lies.
The Keyboard Type is "NumberPad" in IB, as well as Return Key being "done" and Auto-enable Return Key is checked.
It's important to note that if I change the Keyboard Type to "Default" or even "Numbers & Punctuation", the above code is called when the "Done" button is tapped. There's obviously no "done" key in the Number Pad and the above code is never called.
I've progressed a lot at iPhone development since I posted this and worked out how to do it a while ago. Thanks for taking the time to reply though I never posted my solution so it should help some people out.
I've progressed a lot at iPhone development since I posted this and worked out how to do it a while ago. Thanks for taking the time to reply though I never posted my solution so it should help some people out.
Cheers
You should post your code. The instructions above do not work for me. When does the textfield then know to resign the keyboard? Also, the above done method is returning a BOOL when it should be returning void no?
You should post your code. The instructions above do not work for me. When does the textfield then know to resign the keyboard? Also, the above done method is returning a BOOL when it should be returning void no?
1. The done method does not need to return *anything*. Just delete 'return YES'.
2. In order to make this work, via IB, you must set the 'Received Actions' for the First Responder:
a) Select First Responder
b) View Connections Inspector
c) Drag FROM the 'pressDoneKey' Connection (radio button) to the actual TextField.
d) Select 'Did End On Exit' (in the pop-up list of actions)
Save. That's it. It worked for me.
HTH
P.S. BTW, thanks for posting this sequence. Very helpful and appreciated.
I found it easiest to just make sure that after you are through with the keyboard that you disable all the text fields. This will make your keyboard slide away into that good night. For example in one case I have two text fields: username and password. When the person hits the login button or hits go while they are in the final text field on the virtual keyboard it launches an IBACTION method that does this:
HI,
This works fine with the other types of key board. But when we use keyboard type number pad, then doing above process does not brought the "Done key" in number pad. so how could we hide it?
HI,
This works fine with the other types of key board. But when we use keyboard type number pad, then doing above process does not brought the "Done key" in number pad. so how could we hide it?
Hiding it: try this
[textField resignFirstResponder];
I just did a test and the value is there (I checked using a uialertview and having the message be the text property of the textfield.)
EDIT: [textField resignFirstResponder]; works, just have the UITextFieldDelegate in the <> in the .h file.
Last edited by fhsjaagshs; 08-18-2011 at 06:41 PM.
Hiding it: try this
[textField resignFirstResponder];
I just did a test and the value is there (I checked using a uialertview and having the message be the text property of the textfield.)
EDIT: [textField resignFirstResponder]; works, just have the UITextFieldDelegate in the <> in the .h file.
I think the general problem here is if you have a number pad in real device, there is no "done" or "return" key for you to tap, even though you can do that in simulator by real keyboard.