0

I want to make a login system with two textfields. I want the user to edit the first textfield and by clicking next on the keyboard jump over to the next textfield and after editing that he should click go and the system should do it's thing. So what I really want is to be able to jump from one textfield to the next and the most important part get the input text from both fields when the user clicks the go button (witch is on the second field's keyboard). both my text fields are tagged in IB. If it's not very clear I want to implement something very similar to the Podio's app login. This is what I have so far. Any help much appreciated:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    AppSettings *settings = [AppSettings sharedSettings];
    NSString *password;
    NSString *name;

    if(textField == nameTextField)
    {
        name = textField.text;
        NSLog(@"Name text field: %@",name);
    }
    if(textField == passwordTextField)
    {
        password = textField.text;
        NSLog(@"Password text field: %@",password);        
    }

    //this is where I send a call to the server
    [[SessionInfo sharedInfo] loginWithEmail:settings.userEmailFromLogin 
                                     AndName:name AndPasswordRequest:password];

    [textField resignFirstResponder];
    return YES;
}
alex
  • 957
  • 2
  • 9
  • 16

2 Answers2

0
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    AppSettings *settings = [AppSettings sharedSettings];
    NSString *password;
    NSString *name;

    if(textField == nameTextField)
    {
        name = textField.text;
        [passwordTextField becomeFirstResponder];
        NSLog(@"Name text field: %@",name);
    }
    if(textField == passwordTextField)
    {
        password = textField.text;
        [textField resignFirstResponder];
        NSLog(@"Password text field: %@",password); 
        //this is where I send a call to the server
        [[SessionInfo sharedInfo] loginWithEmail:settings.userEmailFromLogin 
                                         AndName:name AndPasswordRequest:password];  
    }
    return YES;
}
yibuyiqu
  • 728
  • 1
  • 7
  • 20
0

@yibuyiqu That didn't really work for me. But I solved my problem of how to get the data out of multiple text fields. One just needs to store the strings from the input into some dictionary object like so:

- (void)textFieldDidEndEditing:(UITextField *)textField 
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    AppSettings *settings = [AppSettings sharedSettings];
    NSString *password;
    NSString *name;

    if ([textField.text isEqualToString:@""])
        return;

    switch (textField.tag) {
        case NameFieldTag:
            name = textField.text;
            [userDefaults setObject:name forKey:kloginName];
            settings.userNameFromLogin = [userDefaults objectForKey:kloginName];
            break;

        case PasswordFieldTag:
            password = textField.text;
            [userDefaults setObject:password forKey:klogginPassword];
            settings.userPasswordFromLogin = [userDefaults objectForKey:klogginPassword];
            break;
        default:
            break;
    }
}

After this I used the solution posted by someone here to go through the textfields from the keyboard https://stackoverflow.com/a/1351090/1339876

Community
  • 1
  • 1
alex
  • 957
  • 2
  • 9
  • 16