0

我正在为我的应用程序创建登录名,但UITextField's响应者有问题。我有 2 个字段,其中一个用于电子邮件,另一个用于密码。第一个,有返回的“下一步”按钮,第二个是“完成”按钮。问题是我正在为这些按钮开发逻辑。textfieldShouldReturn方法是这样的:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{    
    if ([emailField isFirstResponder]) {
        NSLog(@"NEXT");
    } else if ([passwordField isFirstResponder]) {
        [passwordField resignFirstResponder];
    }
    return YES;
}

关于字段的代码:

CGRect frame = CGRectMake(20, 0, 280, 44);

emailField = [[UITextField alloc] initWithFrame:frame];
[emailField setPlaceholder:@"Correo electronico"];
[emailField setKeyboardType:UIKeyboardTypeEmailAddress];
[emailField setReturnKeyType:UIReturnKeyNext];
[emailField setClearButtonMode:UITextFieldViewModeWhileEditing];
[emailField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[emailField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[emailField setAutocorrectionType:UITextAutocorrectionTypeNo];
[emailField setDelegate:self];

passwordField = [[UITextField alloc] initWithFrame:frame];
[passwordField setPlaceholder:@"Contraseña"];
[passwordField setKeyboardType:UIKeyboardTypeDefault];
[passwordField setReturnKeyType:UIReturnKeyDone];
[passwordField setSecureTextEntry:YES];
[passwordField setClearButtonMode:UITextFieldViewModeWhileEditing];
[passwordField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[passwordField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[passwordField setAutocorrectionType:UITextAutocorrectionTypeNo];
[passwordField setDelegate:self];

当我在emailField并按下下一个键时,没有任何反应,但如果我在passwordField并按下完成键,应用程序工作正常并隐藏键盘。

4

3 回答 3

0

这是我的代码

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (textField == fieldUsername) {
        [fieldPassword becomeFirstResponder];
    } else if (textField == fieldPassword) {
        [self doLogin];
    }
    return YES;
}
于 2012-10-09T12:54:20.783 回答
0
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{    
        if (textField == emailField) {
            NSLog(@"NEXT");
            [emailField resignFirstResponder];
            [passwordField becomeFirstResponder];
        }
        else if (textField == passwordField) {
            [passwordField resignFirstResponder];
        }
    return YES;
}
于 2012-10-09T12:55:48.620 回答
0
   - (BOOL)textFieldShouldReturn:(UITextField *)textField
 {    
if ([emailField isFirstResponder]) {
    NSLog(@"NEXT");
   [passwordField becomefirstresponder];///add this 
} else if ([passwordField isFirstResponder]) {
    [passwordField resignFirstResponder];
}
return YES;
}
于 2012-10-09T12:56:42.723 回答