2012-01-12 3 views
0

내 응용 프로그램에서 많은 텍스트 필드를 만들었으며 사용자가 편집을 마치면 키보드를 닫으려고합니다. 나는에 textField의 IB에 의해 생성 및 IBAction를 내가 거기에 사용할 수있다하지만 텍스트 필드의이 같은 만든 경우 경우 프로그래밍 방식으로 didEndOnExit 발생시키기

int top = 60; 
for(NSUInteger i=0; i< [kArray count]; i++){ 
     UITextField *kField = [kArray objectAtIndex:i]; 
     kField.frame = CGRectMake(130, top, 60, 30); 
     kField.borderStyle = UITextBorderStyleRoundedRect; 
     kField.autocorrectionType = UITextAutocorrectionTypeNo; 
     kField.returnKeyType = UIReturnKeyDone; 
     kField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; 

     [scrollView addSubview:kField]; 
     top += 50; 
    } 

가 어떻게 사용자 프레스 버튼을 수행 키보드를 닫을 수 있다는 것을 알고?

답변

2

사용 UITextFieldDelegate 방법 :

@interface MyViewController : UIViewController <UITextFieldDelegate> 
+0

이보기를 할당하는 것을 잊지 마세요

#pragma mark UITextFieldDelegate methods - (BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; return YES; } 

하는 클래스가과 같이 위임을 준수하기 위해 기억 컨트롤러를'kField'의 델리게이트로 사용합니다. 'kField.delegate = self'. –

0

을이 시도 :

- (BOOL)textFieldShouldReturn: (UITextField *)textField { 
    [kField resignFirstResponder]; 
    return YES; 
} 
관련 문제