2014-04-08 6 views
0

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]; 
     } 
+0

텍스트 필드에 대한 대리인을 설정 했습니까? – Flexicoder

+1

게시 한 코드 스 니펫이 너무 자세하지 않습니다 .. 닫으려고하는 키보드의 태그는 무엇입니까? @Flexicoder가 말했듯이, 그 textField에 대한 델리게이트를 올바르게 설정 했습니까? 텍스트 필드의 태그가 14 인 경우, 사용자 디폴트의'NTAuthentication'의 값은'N'입니까? 이 메서드에서 중단 점을 사용하여 코드를 단계별로 실행하여 문제를 격리하고 실행하는 것이 좋습니다. – liamnichols

+0

@Flexicoder 예, 위의 코드가 업데이트되었습니다. – Angie

답변

1

문제는 당신이 UIModalPresentationFormSheet에 있다는 것입니다 모달 뷰 컨트롤러의 뷰. 기본적으로 키보드는이 아니므로 이러한 종류의 모달보기에서 텍스트 필드가 첫 번째 응답자를 사임 할 때 사라집니다. 키보드는 모달 뷰 자체가 해제되거나 (disablesAutomaticKeyboardDismissal을 무시하여 NO를 반환하여 동작을 변경할 수있는 경우에만) 사라집니다.

+0

이것을 명확히하기위한 Thanxs는 ModalPresentationForm – Angie

+1

에 대해 알지 못했습니다. 질문 할 수 있습니다. 왜 내가 UIModalPresentationFormSheet를 사용하고 있다고 생각합니까? breakpointing이'[textField resignFirstResponder]'가 호출되고 있다는 것을 이미 당신의 코멘트에 표시했기 때문입니다. 이제는'textField'가 델리게이트 메서드 호출의 일부로 올바르게 제공 되었기 때문에 'textField'는 nil이 아닙니다. 그렇지 않으면 우리가 처음에는 여기에 없었을 것입니다. 그러므로 우리는 스스로에게 묻습니다 : 어떤 상황에서'resignFirstResponder'는 키보드 해고를하지 않았습니까? 그리고 이것은 주요한 것입니다. – matt