iPad에서 완료 버튼을 누르면 다음 코드가 표시되고 키보드가 닫히지 않습니다.완료시 Keybaord가 닫히지 않음
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if (textField.tag == 13) //Username Field
{
UITableViewCell *cCredentials = [self.tvList cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:CredentialsSection]];
[((UITextField*)[cCredentials viewWithTag:14]) becomeFirstResponder];
}
else if (textField.tag == 14) //Password Field
{
if (![[[NSUserDefaults standardUserDefaults] stringForKey:@"NTAuthentication"] isEqualToString: @"N"])
{
//Domain Field
UITableViewCell *cCredentials = [self.tvList cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:CredentialsSection]];
[((UITextField*)[cCredentials viewWithTag:15]) becomeFirstResponder];
}
else
{
[textField resignFirstResponder];
}
}
else
{
[textField resignFirstResponder];
}
return YES;
}
헤더 파일 대표 :
@interface vcSignature_iPad : UIViewController <DropdownDelegate,
UITextFieldDelegate,
UITextViewDelegate,
UITableViewDataSource,
UITableViewDelegate>
내가 cellForRowAtIndexPath 메서드에 대한 테이블의 필드를 만드는 곳입니다 :
UITableViewCell *cellCredentials = [tableView dequeueReusableCellWithIdentifier:@"cellCredentials"];
if (cellCredentials == nil)
{
cellCredentials = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellCredentials"];
cellCredentials.selectionStyle = UITableViewCellSelectionStyleNone;
cellCredentials.backgroundColor = [UIColor clearColor];
UITextField *txt = [[UITextField alloc]init];
txt.borderStyle = UITextBorderStyleRoundedRect;
txt.font = [UIFont systemFontOfSize:14.0];
txt.textAlignment = NSTextAlignmentLeft;
txt.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
txt.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
txt.delegate = self;
txt.text = nil;
if (indexPath.row == 0)
{
txt.placeholder = @"User Id";
txt.tag = 13;
txt.returnKeyType = UIReturnKeyNext;
txt.frame = CGRectMake(20.0, 10.0, 240.0, 31.0);
txt.text = stored.User;
[cellCredentials.contentView addSubview:txt];
txt = [[UITextField alloc]init];
txt.borderStyle = UITextBorderStyleRoundedRect;
txt.font = [UIFont systemFontOfSize:14.0];
txt.textAlignment = NSTextAlignmentLeft;
txt.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
txt.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
txt.delegate = self;
txt.text = stored.Password;
txt.placeholder = @"Password";
txt.secureTextEntry = YES;
txt.tag = 14;
txt.frame = CGRectMake(279.0, 10.0, 240.0, 31.0);
if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"NTAuthentication"] isEqualToString: @"N"])
{
txt.returnKeyType = UIReturnKeyDone;
}
else
{
txt.returnKeyType = UIReturnKeyNext;
}
[cellCredentials.contentView addSubview:txt];
}
else
{
txt.placeholder = @"Domain";
txt.tag = 15;
txt.returnKeyType = UIReturnKeyDone;
txt.frame = CGRectMake(20.0, 10.0, 240.0, 31.0);
txt.text = stored.Domain;
[cellCredentials.contentView addSubview:txt];
}
텍스트 필드에 대한 대리인을 설정 했습니까? – Flexicoder
게시 한 코드 스 니펫이 너무 자세하지 않습니다 .. 닫으려고하는 키보드의 태그는 무엇입니까? @Flexicoder가 말했듯이, 그 textField에 대한 델리게이트를 올바르게 설정 했습니까? 텍스트 필드의 태그가 14 인 경우, 사용자 디폴트의'NTAuthentication'의 값은'N'입니까? 이 메서드에서 중단 점을 사용하여 코드를 단계별로 실행하여 문제를 격리하고 실행하는 것이 좋습니다. – liamnichols
@Flexicoder 예, 위의 코드가 업데이트되었습니다. – Angie