我正在爲我的應用創建登錄名,並且我遇到了UITextField's
響應者的問題。 我有2個字段,其中一個是電子郵件,另一個是密碼。第一個,有返回的「下一個」按鈕,第二個是「完成」按鈕。 問題是我正在開發該按鈕的邏輯。該textfieldShouldReturn
方法是這樣的:uitextfield響應者的問題
- (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
和按完成關鍵的應用程序工作正常,並隱藏鍵盤。
只要你說,如果passwordField becomeFirstRespoder - passwordField resignFirstResponder :) –
哦它對交配看到兩幀是相同的伴侶.. –