我知道我必须致电
- (BOOL)disablesAutomaticKeyboardDismissal {
return NO;
}
//this dismiss keyboard on ios
- (BOOL) textViewShouldBeginEditing:(UITextView *)textView {
[self.comments resignFirstResponder];
return YES;
}
为了解除表单上的键盘问题,我也知道如果有的话,我必须在导航控制器中调用disablesAutomaticKeyboardDismissal
。
问题是:我使用导航控制器以编程方式创建表单:
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
SettingsViewController *settingsVC = [sb instantiateViewControllerWithIdentifier:@"settingsViewController"];
//add navigation controller
UINavigationController *modalViewNavController= [[UINavigationController alloc] initWithRootViewController:settingsVC];
modalViewNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
modalViewNavController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:modalViewNavController animated:YES];
所以我没有表单的导航控制器类,在这种情况下如何解除键盘?
我是否必须创建导航视图控制器?
UPDATE ::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::
结束在故事板中创建导航控制器并在导航控制器的视图控制器中调用disablesAutomaticKeyboardDismissal
,这解决了问题,但我仍然想知道如何在不创建导航控制器类的情况下执行此操作。
欢迎任何意见......
答案 0 :(得分:2)
您可以尝试以下代码;
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
gestureRecognizer.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:gestureRecognizer];
}
- (void)hideKeyboard {
[self.view endEditing:YES];
}
答案 1 :(得分:0)
以下代码对我有用:
@interface UINavigationController (dismissKeyBoard)
@end
@implementation UINavigationController (dismissKeyBoard)
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}
@end