Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-22-2008, 10:33 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Question Hiding keyboard/number pad

Hey everyone,

This should be quite simple I think. I know to had the keyboard this code is used:


Code:
- (BOOL)textFieldShouldReturn:(UITextField *)textBoxName {
	[textBoxName resignFirstResponder];
	return YES;
}
In IB where you can select keyboard type I have changed it to number pad and this code doesn't seem to work for me.

My IB settings are:

Type: Number Pad
Return Key: Done

And Auto-enable done key is checked.



And help would be appreciated.
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 11-03-2008, 03:58 AM   #2 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 4
Default

I've come up against this too - to make a special button (or even another view?) to close the keyboard is... undesirable...

Did you ever figure this one out?
daimoh is offline   Reply With Quote
Old 11-03-2008, 04:05 AM   #3 (permalink)
Registered Member
 
Jume's Avatar
 
Join Date: Jul 2008
Location: Slovenia, EU
Posts: 264
Send a message via Skype™ to Jume
Default

did you set the delagate for your UITextField variable (I assume that it is IBOutlet if it is linked to IB)?

otherwise the above code is ok, I use the same and it works.
Jume is offline   Reply With Quote
Old 11-03-2008, 04:10 AM   #4 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 4
Default

Hi Jume - most certainly, but none of the events (i've tried) trigger as the Number Pad doesn't have a "done" key. I even tried Touch Up outside...

I've checked the delegate methods are being called too - no problems there...
daimoh is offline   Reply With Quote
Old 11-03-2008, 04:21 AM   #5 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 74
Default

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];
SkylarEC is offline   Reply With Quote
Old 11-03-2008, 04:23 AM   #6 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 4
Default

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.
daimoh is offline   Reply With Quote
Old 11-03-2008, 04:31 AM   #7 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 74
Default

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.
SkylarEC is offline   Reply With Quote
Old 11-03-2008, 05:07 AM   #8 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 4
Default

no problems, I have:
Code:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
	NSLog(@"didendediting");
	[self dismissModalViewControllerAnimated:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
	NSLog(@"should return");
	[textField resignFirstResponder];
	return YES;
}
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.

Is that enough to go on?
daimoh is offline   Reply With Quote
Old 05-30-2009, 05:21 PM   #9 (permalink)
New Member
 
Join Date: May 2009
Posts: 1
Thumbs up iphone Dev Done Key

So You want to add a 'Done' key on iphone , do some specific stuff and make the keywork Invisible .. Then Do the following step.

The Steps below is for when u use Nib file.



1. Open NIb file .. Cliick on view and click on the textbox u want to change the keyboard behavior .

2. Open 'Inspector' from the tool menu and change the return key type to 'done'

3. Go to Connection inspector and change the 'delegate' to file owner of the View Controller ( click on + sign and drag to the File's owner )

4. Create a new method in File owner Controller -(IBAction) pressDoneKey and implement this method

- (IBAction)pressDoneKey
{

[txtClient resignFirstResponder];
return YES;
}

where txtClient is a textfield ..



like this



#import <UIKit/UIKit.h>


@interface ClientGoViewController : UIViewController {

IBOutlet UITextField *txtClient;

}

@property (nonatomic, retain) IBOutlet UITextField *txtClient;

-(IBAction) pressDoneKey;

@end



and U r good to go


Visit Deepak Dhakal..Not that personal | This is about Me, .NET and iPhone Code for more Iphone stuff
Done Key in iPhone keyBoard
therisingdeepak is offline   Reply With Quote
Old 05-30-2009, 05:25 PM   #10 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
Default

Quote:
Originally Posted by therisingdeepak View Post
So You want to add a 'Done' key on iphone , do some specific stuff and make the keywork Invisible .. Then Do the following step.

The Steps below is for when u use Nib file.



1. Open NIb file .. Cliick on view and click on the textbox u want to change the keyboard behavior .

2. Open 'Inspector' from the tool menu and change the return key type to 'done'

3. Go to Connection inspector and change the 'delegate' to file owner of the View Controller ( click on + sign and drag to the File's owner )

4. Create a new method in File owner Controller -(IBAction) pressDoneKey and implement this method

- (IBAction)pressDoneKey
{

[txtClient resignFirstResponder];
return YES;
}

where txtClient is a textfield ..



like this



#import <UIKit/UIKit.h>


@interface ClientGoViewController : UIViewController {

IBOutlet UITextField *txtClient;

}

@property (nonatomic, retain) IBOutlet UITextField *txtClient;

-(IBAction) pressDoneKey;

@end



and U r good to go


Visit Deepak Dhakal..Not that personal | This is about Me, .NET and iPhone Code for more Iphone stuff
Done Key in iPhone keyBoard

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
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 10-27-2009, 12:07 AM   #11 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 4
Default

Quote:
Originally Posted by kieran12 View Post
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?
coxaqui is offline   Reply With Quote
Old 10-30-2009, 08:56 PM   #12 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 1
Default Couple of Tweaks to make it *work*

Quote:
Originally Posted by coxaqui View Post
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.
ScottH is offline   Reply With Quote
Old 11-02-2009, 12:15 AM   #13 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 48
Exclamation Another easy way to do it

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:

[username setEnabled:FALSE];
[password setEnabled:FALSE];

If you set these values to TRUE in viewDidLoad then if you come back to this view all will be back to normal.

Hope this helps!

Nick Powers
encryption is offline   Reply With Quote
Old 03-15-2011, 09:48 AM   #14 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 4
Default

Quote:
Originally Posted by therisingdeepak View Post
So You want to add a 'Done' key on iphone , do some specific stuff and make the keywork Invisible .. Then Do the following step.

The Steps below is for when u use Nib file.



1. Open NIb file .. Cliick on view and click on the textbox u want to change the keyboard behavior .

2. Open 'Inspector' from the tool menu and change the return key type to 'done'

3. Go to Connection inspector and change the 'delegate' to file owner of the View Controller ( click on + sign and drag to the File's owner )

4. Create a new method in File owner Controller -(IBAction) pressDoneKey and implement this method

- (IBAction)pressDoneKey
{

[txtClient resignFirstResponder];
return YES;
}

where txtClient is a textfield ..



like this



#import <UIKit/UIKit.h>


@interface ClientGoViewController : UIViewController {

IBOutlet UITextField *txtClient;

}

@property (nonatomic, retain) IBOutlet UITextField *txtClient;

-(IBAction) pressDoneKey;

@end



and U r good to go


Visit Deepak Dhakal..Not that personal | This is about Me, .NET and iPhone Code for more Iphone stuff
Done Key in iPhone keyBoard



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?
Mandar is offline   Reply With Quote
Old 08-18-2011, 06:35 PM   #15 (permalink)
[[Brain alloc]init];
 
fhsjaagshs's Avatar
 
Join Date: Aug 2011
Location: New Jersey
Age: 15
Posts: 70
Default

Quote:
Originally Posted by Mandar View Post
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.
fhsjaagshs is offline   Reply With Quote
Old 08-23-2011, 11:11 AM   #16 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 1
Default

Quote:
Originally Posted by fhsjaagshs View Post
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.

Leo
leothenerd is offline   Reply With Quote
Reply

Bookmarks

Tags
hide, keyboard, number pad, resign responder

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 255
18 members and 237 guests
2WeeksToGo, @sandris, AdamL, ADY, BrianSlick, Dani77, Dattee, GHuebner, headkaze, mer10, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,747
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:52 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0