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 05-03-2009, 04:02 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
Question 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
lexy0202 is offline   Reply With Quote
Old 05-03-2009, 04:39 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: Belgium
Posts: 106
Default

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)textFieldShouldReturnUITextField *)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.
SkyTrix is offline   Reply With Quote
Old 05-03-2009, 04:57 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 118
Default

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!
lexy0202 is offline   Reply With Quote
Old 05-03-2009, 05:01 AM   #4 (permalink)
Registered Member
 
Join Date: Feb 2009
Location: Belgium
Posts: 106
Default

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
SkyTrix is offline   Reply With Quote
Old 05-25-2009, 05:52 AM   #5 (permalink)
New Member
 
Join Date: May 2009
Posts: 26
Default How to hide keyboard?

Quote:
Originally Posted by lexy0202 View Post
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.
GauravJain is offline   Reply With Quote
Old 05-25-2009, 06:31 AM   #6 (permalink)
Registered Member
 
Join Date: May 2009
Location: Albi, France
Age: 24
Posts: 45
Send a message via MSN to dragon_tenvel
Default

- (BOOL)textFieldShouldReturnUITextField *)aTextField {

if (aTextField == yourTextField)
[yourTextField resignFirstResponder];

return YES;
}
dragon_tenvel is offline   Reply With Quote
Old 05-26-2009, 02:35 AM   #7 (permalink)
New Member
 
Join Date: May 2009
Posts: 26
Default

Hi,
Thanks a lot. The code is working fine.
GauravJain is offline   Reply With Quote
Old 09-16-2009, 01:43 AM   #8 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 14
Default

How can i do same for UITextView.
praveenmatanam is offline   Reply With Quote
Old 09-25-2009, 12:17 AM   #9 (permalink)
Registered Member
 
GoNXaS's Avatar
 
Join Date: Jul 2009
Location: Argentina
Age: 22
Posts: 15
Default

Quote:
Originally Posted by praveenmatanam View Post
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.
GoNXaS is offline   Reply With Quote
Reply

Bookmarks

Tags
enter, key, keyboard, newbie, 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: 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
Powered by vBadvanced CMPS v3.1.0

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