2011-09-29 3 views
0

안녕하세요 사용자 지정 DOne 단추가 구현 된 numpad-keyboard를 닫으려고합니다. 다음은사용자 지정 단추가 숫자 패드에 추가 된 문제

: - '인식 할 수없는 선택기 인스턴스 0x7399b40로 전송 [있는 UIButton 키] :'나는 그것을 때문에 캐치되지 않는 예외 'NSInvalidArgumentException'응용 프로그램 종료, 이유는 다음과 같은 오류 *을 제공 충돌 응용 프로그램을 기각 할 때 코드 조각

// Snippet 
    - (void)keyboardWillShow:(NSNotification *)notification { 
     // create custom button 
    doneButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 
    doneButton.frame = CGRectMake(0, 163, 106, 53); 
    doneButton.adjustsImageWhenHighlighted = NO; 
    [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"]  forState:UIControlStateNormal]; 
    [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted]; 
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside]; 


    // locate keyboard view 
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; 
UIView* keyboard;  
UITextField * tempTextField = (UITextField*)self.currentResponder; //Current responder is the textfield which is clicked 


for(int i=0; i<[tempWindow.subviews count]; i++) { 
    keyboard = [tempWindow.subviews objectAtIndex:i]; 

    if([[[keyboard class]description] hasPrefix:@"UIPeripheralHostView"]) 
    { 

     if(tempTextField.keyboardType == UIKeyboardTypeNumberPad) 
     { 
      UIView *viewToInsertButtonInto = [[[[[[[[keyboard subviews] objectAtIndex:0] subviews]objectAtIndex:0]subviews]objectAtIndex:0]subviews]objectAtIndex:0]; 
      [viewToInsertButtonInto addSubview:self.doneButton]; 
     } 

    } 

} 

}

- (void)doneButton:(id)sender 
{ 
    NSLog(@"%@,%@ _________  %s",self.faxTextField,self.currentResponder,__FUNCTION__); 
    UITextField * tempTextField = (UITextField*)self.currentResponder; 
    if ([tempTextField isFirstResponder]) { 
    NSLog(@"It is the first responder"); 
} 
    [tempTextField resignFirstResponder]; 
} 

앱 충돌 [tempTextField resignFirstResponder]; 실행됩니다.

누군가 도와 드릴 수 있습니까? 감사 나치 켓 왜 u는이 로그를 사용하는

+0

당신이 "키"가 무엇인지 말해 주실 래요 사용 사용한다고 생각? 그것은 방법인가 변수인가? 버튼이 "키"라는 선택기를 호출하려고합니다. –

+0

'doneButton :'메소드에서'faxTextField'라는 textField를 로깅하기 위해 % @를 사용하기 때문에 충돌이 발생한다고 생각합니다. 로그에 textField를 인쇄 할 수 없습니다. 당신이 할 수있는 것은'self.faxTextField.text'를 사용해서 텍스트를 출력하는 것입니다. 또한'self.currentResponder'는 % @ 기호를 사용하여 로그 할 수없는 textField입니다. 희망이 당신을 도와줍니다. –

답변

1
NSLog(@"%@,%@ _________  %s",self.faxTextField,self.currentResponder,__FUNCTION__); 

?

나는 유 NSLog(@"%@,self.faxTextField.text);

또는

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
[textField resignFirstResponder]; 
return NO; 

} 
관련 문제