当完成或触摸文本字段之外的内容时,我不知道如何关闭键盘。这是我尝试的方法
myController.h
@interface myController : UIViewController <UITextFieldDelegate>{
secondViewController *secondView;
}
myController.m
-(void)loadView
{
.....
textFieldRounded.borderStyle = UITextBorderStyleRoundedRect;
textFieldRounded.textColor = [UIColor blackColor];
textFieldRounded.font = [UIFont systemFontOfSize:17.0];
textFieldRounded.placeholder = @"<enter text>";
textFieldRounded.backgroundColor = [UIColor whiteColor];
textFieldRounded.autocorrectionType = UITextAutocorrectionTypeNo;
textFieldRounded.keyboardType = UIKeyboardTypeDefault;
textFieldRounded.returnKeyType = UIReturnKeyDone;
textFieldRounded.clearButtonMode = UITextFieldViewModeWhileEditing;
[textFieldRounded.delegate = self;
[self.view addSubview:textFieldRounded];
....
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
return [textField resignFirstResponder];
}
最佳答案
用途:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
当您触摸文本字段之外时进行捕获
关于objective-c - 无法关闭键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9113264/