在我的視圖中,我有3個UITextField,對於他們每個我創建了一個用於鍵盤的accessoryView,如apple所解釋的。ResignFirstResponder from Keyboard AccessoryView按鈕
在我的accessoryView中,我添加了一個必須調用函數「CloseKeyboard」的按鈕。在這個函數中,我找不到一種方法來截取鍵盤正在寫入的UITextField,並且我需要調用ResignFristResponder。
要在一個字段添加accessoryView的我寫的代碼
if (field1.inputAccessoryView == nil) {
field1.inputAccessoryView = [self createInputAccessoryView];
}
if (field2.inputAccessoryView == nil) {
field2.inputAccessoryView = [self createInputAccessoryView];
}
if (field3.inputAccessoryView == nil) {
field3.inputAccessoryView = [self createInputAccessoryView];
}
這裏createInputAccessory功能:
-(UIView *)createInputAccessoryView {
CGRect accessFrame = CGRectMake(0.0, 0.0, 20.0, 55.0);
UIView *inputAccessoryView = [[UIView alloc] initWithFrame:accessFrame];
UIButton *compButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
compButton.frame = CGRectMake(250.0, 10.0, 60.0, 40.0);
[compButton setTitle: @"Close" forState:UIControlStateNormal];
[compButton addTarget:self action:@selector(CloseKeyboard:)
forControlEvents:UIControlEventTouchUpInside];
[inputAccessoryView addSubview:compButton];
return inputAccessoryView; }
我怎樣才能實現「CloseKeyboard」功能,能夠從積極的UITextField到resignFirstResponder ?
謝謝你的幫助!