Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 28, 2008, 06:16 PM   #1
fenrus110
macrumors regular
 
Join Date: Mar 2008
iPhone Keyboard, how to make Return key work?

I'm using a UITextField and I am guessing that I need to use UITextFieldDelegate somehow to make the Return key actually do something. (like exit the keyboard mode)

I looked at:
HelloWorldClassic, but the Return key doesn't do anything.
UIShowCase, but it's just full of subclass upon subclass confusion.
SQLLiteBooks, but again, full of subclass confusion.

I'm a XCode newb, so can anyone explain or provide a quick and dirty example of how to make the keyboard work as intended?
fenrus110 is offline   0 Reply With Quote
Old Mar 29, 2008, 03:17 AM   #2
AndyQ
macrumors newbie
 
Join Date: Mar 2008
What I did was the following:

When setting up the textfield, add an extra line that looks like:
myTextField.returnKeyType = UIReturnKeyDone;

You may also need the following line:
myTextField.delegate = self;

Then you need to add a function:

// this helps dismiss the keyboard then the "done" button is clicked
- (BOOL)textFieldShouldReturnUITextField *)textField
{
[textField resignFirstResponder];
return YES;
}

That works for me.
AndyQ is offline   0 Reply With Quote
Old Mar 29, 2008, 03:36 AM   #3
benlangdon
macrumors 65832
 
benlangdon's Avatar
 
Join Date: Jan 2008
Send a message via AIM to benlangdon
ugh this just makes me want to go in the fetal position because of this program i need to write that is due monday and have put off for 3 weeks
__________________
MBP | 2.2 ghz | bunch of ExHd's | Westinghouse L1916HW - Ergotron lx | Sony STR-DG520
iPod | 30 gb | Westone UM1 | Beyer DT770
benlangdon is offline   0 Reply With Quote
Old Mar 29, 2008, 04:56 PM   #4
fenrus110
Thread Starter
macrumors regular
 
Join Date: Mar 2008
@AndyQ

Okay I see that. Now just one step further, what if I have two UITextField's? ie. username/password.

Will the textFieldShouldReturnUITextField function be now listening to both UITextField's? Shouldn't they be separated?
fenrus110 is offline   0 Reply With Quote
Old Mar 30, 2008, 02:47 AM   #5
AndyQ
macrumors newbie
 
Join Date: Mar 2008
Do you want the same behaviour on both text fields?

If so, you don't need to do anything else otherwise in the textFieldShouldReturn method just see which field the textField points to and handle accordingly

e.g.
if ( textField == usernameField )
{
..
}
AndyQ is offline   0 Reply With Quote
Old Mar 30, 2008, 08:42 PM   #6
fenrus110
Thread Starter
macrumors regular
 
Join Date: Mar 2008
Quote:
Originally Posted by AndyQ View Post
Do you want the same behaviour on both text fields?

If so, you don't need to do anything else otherwise in the textFieldShouldReturn method just see which field the textField points to and handle accordingly

e.g.
if ( textField == usernameField )
{
..
}
hmm... massive if/else statements, seems like a similar event mechanism used in Java... (which I hate)
fenrus110 is offline   0 Reply With Quote
Old Mar 30, 2008, 09:50 PM   #7
DaveGee
macrumors 6502a
 
Join Date: Jul 2001
Quote:
Originally Posted by fenrus110 View Post
hmm... massive if/else statements, seems like a similar event mechanism used in Java... (which I hate)
So your writing a program where the enter key when used in the 1st text box on the screen will perform one way and in the text input box directly below it the enter key will behave in an entirely different manner?

D
DaveGee is offline   0 Reply With Quote
Old Mar 31, 2008, 08:35 AM   #8
Monkaaay
macrumors 6502
 
Join Date: Jun 2006
Location: Richmond, VA
Quote:
Originally Posted by benlangdon View Post
ugh this just makes me want to go in the fetal position because of this program i need to write that is due monday and have put off for 3 weeks
Always a bad idea.
Monkaaay is offline   0 Reply With Quote
Old Apr 4, 2008, 03:43 AM   #9
jdhouse4
macrumors newbie
 
Join Date: Jul 2002
Location: Austin, Texas
Send a message via AIM to jdhouse4
From UITextField to UITextField...

I'm running into the same problem. In "normal" IB, the NSTextField responder chain can be easily set through "nextKeyView". But not in IB for iPhone Touch app interfaces. Sad...

You can see a screenshot of my sample app at Cocoacoderblog.com.

Here's what I want for events. First, upon touching UITextField nameField, a keyboard should come up that has not only "Next" for its return key, but maybe even "Return" instead but with "Previous" and "Next" on the navigation bar of the keyboard, much as one gets when using the iPhone's Safari in a multi-field setting.

When I hit "Next", the focus goes from the first UITextField nameField to UITextField ageField. Upon completing the age, touch the "Return" key and the action should occur.

I've tried calling the UITextField delegate textFieldShouldReturn to get this to work, but need to include something...just not sure what.
__________________
jdhouse4 is offline   0 Reply With Quote
Old Apr 9, 2008, 01:01 AM   #10
jdhouse4
macrumors newbie
 
Join Date: Jul 2002
Location: Austin, Texas
Send a message via AIM to jdhouse4
was it something I said?

Ok, where did everyone go?
__________________
jdhouse4 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
IPHONE 4 how to JAILBREAK AND UNLOCK bs2511feist Jailbreaks and iOS Hacks 6 Apr 14, 2012 05:52 PM
How to make F1-F12 keys work as function ONLY for specific app? Pilsen Mac OS X 10.7 Lion 1 Nov 23, 2011 01:15 AM
how to make an iso into a img (does not work as an .iso) mud25 Mac Basics and Help 2 Jul 19, 2011 09:30 PM
Spilled some soda on my early 2008 keyboard... how to rid sticky keys 88888888 MacBook Pro 3 Jun 9, 2009 06:48 PM
How to make Dell 2005fpw work with ibook reverseco PowerPC Macs 3 Mar 15, 2006 09:31 PM


All times are GMT -5. The time now is 12:34 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC