0

I am creating a sample web application on my iphone... In that application the main page is login page....Users enter their user name and password in the textfield (UITextField), it will verified by program.

My problem is I want to move cursor from One uitextfield to another uitextfield using tab key pressed in the keyboard (Like a windows operation).

How can I do this?

Cœur
  • 32,421
  • 21
  • 173
  • 232

1 Answers1

1

You can move the focus to a particular UITextField by calling:

[myTextField becomeFirstResponder]

If you implement the UITextFieldDelegate in your class by declaring the following method you can handle the "Done" key being pressed on the keyboard, which is the iPhone native app equivalent of pressing tab.

/*****************************************************************************/
/* Handle the Done button being pressed on the keyboard for any of our       */
/* editable UITextFields.  We either pass the keyboard focus to the next     */
/* text field, or we hide the keyboard.                                      */
/*****************************************************************************/
- (BOOL)textFieldShouldReturn:(UITextField *)xiTextField 
{        
  if (xiTextField == myAccountNameTextField]) 
  {
    NSLog(@"Done pressed whilst in account name field, pass focus");
    [myPasswordTextField becomeFirstResponder];
  }
  else
  {
    NSLog(@"No next text field, closing keyboard");
    [xiTextField resignFirstResponder];  
  }
}
Dan J
  • 24,430
  • 17
  • 95
  • 168