0

I have 2 text fields, one is for usrname and the other one is for password.

Question : after entering a username and hit next from the keyboard, how can I jump to the password field for typing a password..

Any comments are welcomed here.

tranvutuan
  • 6,089
  • 8
  • 47
  • 83

3 Answers3

2

Check this question. It pretty much clarifies on how to implement what Juan said. How to navigate through textfields (Next / Done Buttons)

Community
  • 1
  • 1
erran
  • 1,300
  • 2
  • 15
  • 36
1

You need to implement the UITextFieldDelegate protocol and use the becomeFirstResponder method to change the focus to the next textField.

The method you need to implement on the delegate is textFieldShouldReturn:.

This is a sample implementation I have:

-(BOOL) textFieldShouldReturn:(UITextField *)textField 
{
    [passwordField becomeFirstResponder];

    if (self.passwordField == textField) {
        [self loginAction:textField];
    }

    return YES;
}

You can set the implementing class delegate for both of your text fields.

Hope it helps!

1

What would you like to have to signify that someone has finished typing? Whatever that condition is, just use the

[myTextField becomeFirstResponder];

method to make the next text field be in control of the keyboard. Effectively this will create the "jump".

Furthermore, you can do this to hook up the next button to be the trigger for the jump.

//amount received animations
[myTextField setDelegate:self];
[myTextField setReturnKeyType:UIReturnKeyDone];
[myTextField addTarget:self
                action:@selector(methodThatJumps:)
      forControlEvents:UIControlEventEditingDidEndOnExit];

and in the method that jumps, simply use the above line. Let me know if you'd like me to explain it better.

Tanvir Ahmed
  • 813
  • 6
  • 9