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 06-04-2009, 10:34 AM   #1 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 44
Exclamation I need help getting my keyboard to retract(disappear)

I know this has been mentioned many times in this forum, but I have searched and could not get any of them to work.

I need a code to have my keyboard go back down after the user presses the return button or touches somewhere else on the screen. This code needs to be all programmatic as I did not use Interface Builder for this. I hope someone can help.

here is my code in the .m file
Code:
- (void)viewDidLoad {
	CGRect frame = CGRectMake(20.0, 68.0, 280.0, 31.0);
	UITextField *textField = [[UITextField alloc] initWithFrame:frame];
	
	self.string = textField.text;
	

	
    textField.textAlignment = UITextAlignmentLeft;
	
    textField.borderStyle = UITextBorderStyleBezel;

	
    textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
	
    textField.keyboardType = UIKeyboardTypeAlphabet;
	
    textField.returnKeyType = UIReturnKeyDefault;
	
	textField.textColor = [UIColor redColor];
	[textField resignFirstResponder];
	
    [self.view addSubview:textField];
Thanks in advance
shabzcohelp is offline   Reply With Quote
Old 06-04-2009, 11:27 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 246
Default

Quote:
Originally Posted by shabzcohelp View Post
I know this has been mentioned many times in this forum, but I have searched and could not get any of them to work.

I need a code to have my keyboard go back down after the user presses the return button or touches somewhere else on the screen. This code needs to be all programmatic as I did not use Interface Builder for this. I hope someone can help.

here is my code in the .m file
Code:
- (void)viewDidLoad {
	CGRect frame = CGRectMake(20.0, 68.0, 280.0, 31.0);
	UITextField *textField = [[UITextField alloc] initWithFrame:frame];
	
	self.string = textField.text;
	

	
    textField.textAlignment = UITextAlignmentLeft;
	
    textField.borderStyle = UITextBorderStyleBezel;

	
    textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
	
    textField.keyboardType = UIKeyboardTypeAlphabet;
	
    textField.returnKeyType = UIReturnKeyDefault;
	
	textField.textColor = [UIColor redColor];
	[textField resignFirstResponder];
	
    [self.view addSubview:textField];
Thanks in advance
texField becomes the first responder when the user touches the textField. To dismiss textField, you should then send it the resignFirstResponder message. Here it appears you are sending the resignFirstResponder message before textField even appears.

You might also make sure that you've set your viewContoller to be the delegate of the textField.
dapis is offline   Reply With Quote
Old 06-04-2009, 11:34 AM   #3 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 44
Default

Quote:
Originally Posted by dapis View Post
texField becomes the first responder when the user touches the textField. To dismiss textField, you should then send it the resignFirstResponder message. Here it appears you are sending the resignFirstResponder message before textField even appears.

You might also make sure that you've set your viewContoller to be the delegate of the textField.
Would there be a way you could show me how exactly I would do that. I would really appreciate the help. I have been trying to figure this out for quite some time.

Thanks for response
shabzcohelp is offline   Reply With Quote
Old 06-04-2009, 11:47 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 246
Default

Quote:
Originally Posted by shabzcohelp View Post
Would there be a way you could show me how exactly I would do that. I would really appreciate the help. I have been trying to figure this out for quite some time.

Thanks for response
This is one of the most common things in iPhone code. You will easily find tons of examples of how to do this in various books, and/or with a Google Search.

Apple's online code examples also have several illustrations of this. For instance, see the UICatalog example.
dapis is offline   Reply With Quote
Old 06-04-2009, 11:58 AM   #5 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 44
Default

Quote:
Originally Posted by dapis View Post
This is one of the most common things in iPhone code. You will easily find tons of examples of how to do this in various books, and/or with a Google Search.

Apple's online code examples also have several illustrations of this. For instance, see the UICatalog example.
Amazing, thank you so much. Just checked out the UICatalog project and it has tons of information that I needed.
Thanks again, I really appreciate it
shabzcohelp is offline   Reply With Quote
Reply

Bookmarks

Tags
keyboard, text field, textfield

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: 243
14 members and 229 guests
ADY, CKAmike, Dani77, dessicant, Duncan C, HemiMG, jakerocheleau, nick.keroulis, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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