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-08-2009, 01:41 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: North America
Posts: 50
Default Using the keyboard -- setting target - action with Done button on the keyboard

I've been looking through documentation and sample code and it almost always uses an external button to dismiss the keyboard and return what's in the text. I want to know how you set the target-action on the "Done" or "Return" or whatever button on the keyboard so that when you're done typing, the keyboard disappears, the view changes, the text is returned etc.

How do you access that "Done" button?

I also tried
[userNameInput addTarget:self action:@selector(editingOver: ) forControlEvents:UIControlEventEditingDidEndOnExit];

but the control event doesn't seem to return unless you actually exit the text field...?

I think my main problem is setting the target - action method... I tried with a simple button, couldn't get it to work...

Thanks

Last edited by shimmy; 09-08-2009 at 02:12 PM.
shimmy is offline   Reply With Quote
Old 09-09-2009, 12:55 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Most likely what you are seeing isn't being done to the keyboard directly. The other button is telling the text field to resignFirstResponder, and that's what makes the keyboard go away. This would be done in the IBAction that you assign to the button.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 09-09-2009, 01:33 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 186
Default

you can create a IBAction and in IB hook up to the textfield's DidEndOnExit event, and in the method just dismiss the keyboard (or "resign" it), and finish out with the rest of your method. I didn't run this but off the top of my head I feel like that's the proper way to do it
rywola is offline   Reply With Quote
Old 09-09-2009, 02:14 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: North America
Posts: 50
Default

One should be able to do it with or without Interface Builder -- I mean its basically equibalent. Why isn't the setAction method working?
shimmy is offline   Reply With Quote
Old 09-09-2009, 02:25 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 186
Default

Quote:
Originally Posted by shimmy View Post
One should be able to do it with or without Interface Builder -- I mean its basically equibalent. Why isn't the setAction method working?
I just assumed you (OP?) would be fine using IB. I prefer doing (most) everything programmatic as well, I just saw this as the easiest way to do it. I think you meant "equivalent" by the way, I mention the typo because I bothered going on to dictionary.com to get no matches, before realizing it was a typo.
rywola is offline   Reply With Quote
Old 09-09-2009, 10:44 AM   #6 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: North America
Posts: 50
Default

Quote:
Originally Posted by rywola View Post
I just assumed you (OP?) would be fine using IB. I prefer doing (most) everything programmatic as well, I just saw this as the easiest way to do it. I think you meant "equivalent" by the way, I mention the typo because I bothered going on to dictionary.com to get no matches, before realizing it was a typo.
Great, but what about my question?
shimmy is offline   Reply With Quote
Old 09-09-2009, 10:59 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 792
Default

You should implement the textfield delegate method below, it is called when you click the Done button on the keyboard
Code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	[textField resignFirstResponder]; //dismiss the keyboard
        //do whatever else you need with the text
nobre84 is offline   Reply With Quote
Old 10-19-2009, 02:55 PM   #8 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: Texas
Posts: 4
Default One more tidbit.

While this works well, I might add that if you don't have the Delegate set to the First Responder (Top item "delegates" under Outlets on the Nib Connections Inspector view (Command-2)) then no matter what, it won't dismiss that silly keyboard! I struggled for hours with that, and used a "touch anywhere else on the screen" workaround before figuring that out.

Frustrating, to say the least. Boy, do I miss VB6!

Phil

Huffco Consulting
www.huffcoconsulting.com

Quote:
Originally Posted by nobre84 View Post
You should implement the textfield delegate method below, it is called when you click the Done button on the keyboard
Code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	[textField resignFirstResponder]; //dismiss the keyboard
        //do whatever else you need with the text
phuffstatler is offline   Reply With Quote
Old 11-11-2009, 10:45 AM   #9 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 3
Default

If your are using UITextView, and have header interface implementing <UITextViewDelegate> the answer is different than for a textfield. Often it is best to have a button above the keyboard to dismiss it, but you can trigger return from the DONE/return key:
Code:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range 
 replacementText:(NSString *)text
{
int charINTtyped=0;
	if([text length]>0){
		charINTtyped=(int)[text characterAtIndex:0];
        }
        if(charINTtyped==10){
             [textView resignFirstResponder]; //dismiss the keyboard
             return NO;//don't insert return into textView.text
        }
        return YES;
}
jdpmdphd is offline   Reply With Quote
Reply

Bookmarks

Tags
donei, keyboard, text, uitextfield

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: 279
20 members and 259 guests
ADY, Bertrand21, Dani77, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84, Sunny46
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
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:00 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0