模态对话框不会关闭键盘 [英] Modal Dialog Does Not Dismiss Keyboard

查看:114
本文介绍了模态对话框不会关闭键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,当在一个 UITextField UITextView 中留下键盘时,键盘不会被解雇 UIModalPresentationFormSheet 。另外,我创建了一个大按钮作为视图的背景,因此如果用户点击字段之外它会被触发。我在常规视图控制器中使用相同的代码,它按预期工作。在模态视图控制器中它什么都不做。任何建议都将不胜感激。

I am running into an issue where the keyboard does not get dismissed when leaving a UITextField or UITextView in a UIModalPresentationFormSheet. In addition, I've created a large button to serve as the view's background so if the user taps outside the fields it gets triggered. I am using the same code in a regular view controller, and it works as expected. In the modal view controller it does nothing. Any suggestions would be appreciated.

- (BOOL)textFieldShouldReturn:(id)sender {  
 [titleTextField resignFirstResponder];
 return YES;
}

- (BOOL)textViewShouldReturn:(id)sender {  
 [synopsisTextView resignFirstResponder];
 return YES;
}

- (IBAction)textFieldDoneEditing:(id)sender {  
 [sender resignFirstResponder];
} 

- (IBAction)textViewDoneEditing:(id)sender {  
 [sender resignFirstResponder];
} 

- (IBAction)backgroundClick:(id)sender {  
 [titleTextField resignFirstResponder];
 [synopsisTextView resignFirstResponder];
}


推荐答案

覆盖 disablesAutomaticKeyboardDismissal 返回NO,如下所示修复了我的同样问题。您应该将此代码放入视图控制器,从中启动键盘:

Overriding disablesAutomaticKeyboardDismissal to return NO as below fixed the same problem of mine. You should put this code to your view controller, from which you initiate the keyboard:

- (BOOL)disablesAutomaticKeyboardDismissal {
    return NO;
}

另外,请检查 SO 问题,如果你想得到详细的解释。

Also, check this SO question if you want to get a detailed explanation.

这篇关于模态对话框不会关闭键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆