2012-02-17 1 views
2

iOSOpenDev를 사용하여 알림 센터를 구성하고 있습니다. UIViewUITextField이 있고 UITextFieldDelegate 프로토콜이 구현되어 있습니다.iOS 5 WeeApp에서 UITextField 지우기 버튼이 작동하지 않는 이유는 무엇입니까?

내 문제는 textFieldShouldClear 메서드가 UITextField의 지우기 단추를 클릭 할 때 호출되지 않는다는 것입니다. shouldChangeCharactersInRange 및 textFieldShouldReturn과 같은 다른 인터페이스 메서드는 문제없이 호출됩니다.

인터페이스 메소드가 호출되지 않는 이유는 무엇입니까?

답변

0

텍스트 필드의 대리인이 자기 있는지 확인 ...

+0

textField의 위임은 이미 self로 설정되어 있지만 차이는 없습니다. – icecreamhead

+0

UITextfield 대리자를 변경하는 항목을 찾아서 (자동으로 설정하는 항목 제외) 주석 처리하십시오. 그런 다음 작동하는지 확인하십시오. 나는 당신의 상황에서 NSLog가 어렵 기 때문에 파일에 쓰는 것을 사용할 것입니다. –

1

theTextField.delegate = self; 

내가 UIActionSheet가 UITextFieldDelegate 프로토콜을 빨아 들었으며, 알림 센터는 동일한 기능을 수행 할 수있는 나는이 문제를 가지고 있었다 사용자가 화면의 다른 곳을 탭했을 때 키보드를 닫을 때. 제스처 인식기를 사용하여 탭을 찾고 탭이 감지되면 텍스트 필드에서 resignFirstResponder를 호출합니다. 불행하게도, 그것은 명확한 버튼을 깨뜨린다. 그들이 약간의 수동 버튼을 탭 트리거 할 필요가 복잡, 테이블 뷰 밖에있는 확인하기 위해 탭을 필터링이었다 내가했던

: 그레이엄 특권의 대답에 따라

// In: - (void)handleTap:(UITapGestureRecognizer *)sender { 
// The user tapped outside a text field, drop the keyboard. 
// Unfortunately this normally breaks the clear button, so we'll check that the 
// tap is outside the table view (and therefore not on a clear button). 
BOOL inButton = CGRectContainsPoint(self.signInButton.bounds, [sender locationInView:self.signInButton]); 
BOOL inTable = CGRectContainsPoint(self.tableView.bounds, [sender locationInView:self.tableView]); 
if (!inTable && !inButton) { 

    BOOL didEndEditing = [self.view endEditing:NO]; 

    // But... if we were editing a field (& therefore the keyboard is showing), 
    // and if they tapped the sign in button, sign in. Not sure where the 
    // onSignIn event is getting lost. The button does highlight. But the 
    // call to endEditing seems to eat it. 
    if (didEndEditing && inButton) { 
     [self onSignIn:self.signInButton]; 
    } 
} 
0

을 내 resignFirstResponder 호출을 할 수 변경 :

[self.focusInput performSelector: @selector(resignFirstResponder) 
         withObject: nil 
         afterDelay: 0.2f]; 

이제 키보드는 의도 한대로 자동으로 숨겨 지지만 지우기 버튼 기능이 다시 나타납니다.

관련 문제