我的UITextField我有的UITextField和@property ID <UITextFieldDelegate>
@property (nonatomic, assign) id <UITextFieldDelegate> delegate;
按下keybord一個完成按鈕後,就應該解僱。有人可以告訴我如何使用這個屬性來做到這一點?
我的UITextField我有的UITextField和@property ID <UITextFieldDelegate>
@property (nonatomic, assign) id <UITextFieldDelegate> delegate;
按下keybord一個完成按鈕後,就應該解僱。有人可以告訴我如何使用這個屬性來做到這一點?
鍵盤的解聘不通過成爲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
鏈接didEndOnExit到具有[自resignFirstResponder]
哦,THX的,但真的不明白究竟是什麼做的 self.textField.delegate =自我; – user1248568 2012-03-04 20:45:20
self.textField應該是您希望能夠關閉鍵盤的文本框。您正在將其委派分配爲「self」,即您的視圖控制器。您的視圖控制器將成爲您的文本字段的代表。 – 2012-03-04 22:44:02