05-03-2009, 04:02 AM
#1 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
iPhone Keyboard
Hi Guys - newbie iPhone developer here:
I know how to remove a keyboard from a UITextField in code, but how do you make an action happen when you press the return or 'done' key... I have tried lots of the events in IB, and they don't seem to do the job.
Alex
05-03-2009, 04:39 AM
#2 (permalink )
Registered Member
Join Date: Feb 2009
Location: Belgium
Posts: 106
Add the UITextFieldDelegate in your class. Here some quote from the documents:
textFieldShouldReturn:
Asks the delegate if the text field should process the pressing of the return button. This method is optional.
- (BOOL)textFieldShouldReturn
UITextField *)textField
Parameters
textField
The text field whose return button was pressed.
Return Value
YES if the text field should implement its default behavior for the return button; otherwise, NO.
Discussion
The text field calls this method whenever the user taps the return button.
You can use this method to implement any custom behavior when the button is tapped.
05-03-2009, 04:57 AM
#3 (permalink )
Registered Member
Join Date: Apr 2009
Posts: 118
Sorry, could you explain SLOWLY how to do this in code, as in... I press the return key on my keyboard, it runs my method for me!
05-03-2009, 05:01 AM
#4 (permalink )
Registered Member
Join Date: Feb 2009
Location: Belgium
Posts: 106
First you need to add the delegate to your viewController or class. So in your header file:
From this:
@interface FirstViewController : UIViewController {
To this:
@interface FirstViewController : UIViewController <UITextFieldDelegate> {
Than, in your .m file, create this method:
Code:
- (BOOL)textFieldShouldReturnUITextField *)textField
{
[self myMethodToRun];
return YES;
}
That's just from the top of my head, but I think it'll work
05-25-2009, 05:52 AM
#5 (permalink )
New Member
Join Date: May 2009
Posts: 26
How to hide keyboard?
Quote:
Originally Posted by
lexy0202
Hi Guys - newbie iPhone developer here:
I know how to remove a keyboard from a UITextField in code, but how do you make an action happen when you press the return or 'done' key... I have tried lots of the events in IB, and they don't seem to do the job.
Alex
Hi Alex, could you please tell me the code to remove the keyboard in Iphone simulator once I am done with adding text in the text field.
05-25-2009, 06:31 AM
#6 (permalink )
Registered Member
Join Date: May 2009
Location: Albi, France
Age: 24
Posts: 45
- (BOOL)textFieldShouldReturn
UITextField *)aTextField {
if (aTextField == yourTextField)
[yourTextField resignFirstResponder];
return YES;
}
05-26-2009, 02:35 AM
#7 (permalink )
New Member
Join Date: May 2009
Posts: 26
Hi,
Thanks a lot. The code is working fine.
09-16-2009, 01:43 AM
#8 (permalink )
Registered Member
Join Date: May 2009
Posts: 14
How can i do same for UITextView.
09-25-2009, 12:17 AM
#9 (permalink )
Registered Member
Join Date: Jul 2009
Location: Argentina
Age: 22
Posts: 15
Quote:
Originally Posted by
praveenmatanam
How can i do same for UITextView.
Hiii
in UITextView theres a metod for that:
- (BOOL)endEditing: (BOOL)force
giving TRUE by parameter the keybord goes down.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 252
24 members and 228 guests
@sandris , ADY , Dani77 , diyora , FAED , fredidf , F_Bryant , GHuebner , HDshot , iDifferent , JasonR , mer10 , Oral B , prchn4christ , Rudy , smithdale87 , Speed , spiderguy84 , stekki , tgjorgoski , Thompson22 , Touchmint , twerner , vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,752
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris