0

我想制作一个带有两个文本字段的登录系统。我希望用户编辑第一个文本字段,然后单击键盘上的下一步跳转到下一个文本字段,编辑后他应该单击 go 并且系统应该这样做。所以我真正想要的是能够从一个文本字段跳转到下一个文本字段,最重要的部分是当用户单击开始按钮时从两个字段中获取输入文本(女巫在第二个字段的键盘上)。我的两个文本字段都在 IB 中标记。如果不是很清楚,我想实现与 Podio 的应用登录非常相似的东西。这就是我到目前为止所拥有的。非常感谢任何帮助:

- (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;
}
4

2 回答 2

0

@yibuyiqu 那对我来说真的不起作用。但我解决了如何从多个文本字段中获取数据的问题。只需将输入中的字符串存储到某个字典对象中,如下所示:

- (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;
    }
}

在此之后,我使用此处某人发布的解决方案从键盘https://stackoverflow.com/a/1351090/1339876浏览文本字段

于 2012-04-19T12:37:11.703 回答
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;
}
于 2012-04-18T00:03:09.953 回答