2012-03-04 42 views

回答

2

鍵盤的解聘不通過成爲UITextField的委託僅僅發生的方法。你的代表必須解僱它。

在您的控制器必須將該委託,或在界面生成器設置它的viewDidLoad

- (void)viewDidLoad { 
    self.textField.delegate = self; 
} 

然後在你的控制器,實現以下的委託方法。

#pragma mark - UITextFieldDelegate 

// This method gets called when you hit the enter key on the keyboard, 
// or in this case 'DONE'. The textfield is asking if it should put 
// a carriage return in the field. This is our opportunity to dismiss 
// the keyboard. 

- (BOOL)textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; // This is what hides the keyboard 

    return NO; 
} 

延伸閱讀:

Responder Chain - developer.apple.com
UITextFieldDelegate Protocol Reference - developer.apple.com

+0

哦,THX的,但真的不明白究竟是什麼做的 self.textField.delegate =自我; – user1248568 2012-03-04 20:45:20

+0

self.textField應該是您希望能夠關閉鍵盤的文本框。您正在將其委派分配爲「self」,即您的視圖控制器。您的視圖控制器將成爲您的文本字段的代表。 – 2012-03-04 22:44:02

0

鏈接didEndOnExit到具有[自resignFirstResponder]

相關問題