模态对话框不会关闭键盘

编程入门 行业动态 更新时间:2024-10-06 09:20:11
本文介绍了模态对话框不会关闭键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到了一个问题,当在一个 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.

更多推荐

模态对话框不会关闭键盘

本文发布于:2023-11-28 04:19:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640931.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   键盘   模态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!