2012-05-14 3 views
3

원시 Objective-C에서이 작업을 수행하는 방법에 대한 많은 예가 있지만 MonoTouch의 C# 코드에서 동일한 작업을 수행하는 방법의 예는 찾을 수 없습니다.프로그래밍 방식으로 키보드를 Monotouch에서 닫는 방법

사용자가 돌아 가기 키를 누를 때 팝업되는 키보드를 닫으려고합니다.

편집 중입니까? 트래핑 할 올바른 이벤트입니까? 첫 번째 응답자 메서드 호출을 취소 할 수 없습니다.

도움 주시면 감사하겠습니다.

답변

3

표본을 보려면 here을보십시오.

일반적으로 샘플에 연결하면 훨씬 쉽습니다. 사람들은 원하는 것을 정확히보고 MonoTouch를 사용하여 그렇게하는 방법을 알려줍니다. 또한 자신 만의 부분적이거나 일하지 않는 코드를 제공하는 것이 큰 도움이됩니다.

0

TouchesBegan() 방법에서 평소와 같이 모든 텍스트 상자에 textbox.ResignFirstReponder()을 입력하거나 View.EndEditing(true);이라고 입력하면됩니다. 물론, 당신이 어딘가에 UIViewController으로부터 상속 받고 그러한 이벤트가있는 경우에만 가능합니다.

+0

. 그 트릭을 할 것으로 보인다. – rams

3

Here is gist showing 숫자 키보드 위에 닫기 버튼을 추가하는 방법. 이 확장 방법을 사용하여 1LOC

myTextField.SetKeyboardEditorWithCloseButton(UIKeyboardType.NumberPad); 

으로이 작업을 수행 할 수 있습니다 나는 DidEndEditing 이벤트를 갇혀 보낸 사람에() ResignFirstResponder라는

public static void SetKeyboardEditorWithCloseButton (this UITextField txt, UIKeyboardType  keyboardType, string closeButtonText = "Done") 
{ 
    UIToolbar toolbar = new UIToolbar(); 
    txt.KeyboardType = keyboardType; 
    toolbar.BarStyle = UIBarStyle.Black; 
    toolbar.Translucent = true; 
    toolbar.SizeToFit(); 
    UIBarButtonItem doneButton = new UIBarButtonItem (closeButtonText, UIBarButtonItemStyle.Done, 
                 (s, e) => { 
     txt.ResignFirstResponder(); 
    }); 
    toolbar.SetItems (new UIBarButtonItem[]{doneButton}, true); 

    txt.InputAccessoryView = toolbar; 
} 

numeric keyboard with closing button http://moocode.net/img/numeric_editor.png

관련 문제