[英]UITextView in custom inputaccessoryView not resigning first responder status
I have a chat application that implements a floating text input field (similar to the iOS Messages app) as the inputAccessoryView
of my ChatViewController
(see Apple's documentation ).我有一个聊天应用实现了一个浮动文本输入框(类似于iOS的消息应用程序)作为inputAccessoryView
我的ChatViewController
(见苹果的文档)。
class ChatViewController: UIViewController {
override var inputAccessoryView: UIView? {
return chatInputView
}
override var canBecomeFirstResponder: Bool {
return true
}
...
My ChatViewController
has a ChatTableViewController
child view controller, which has cells containing UITextField
s whose text content is editable.我的ChatViewController
有一个ChatTableViewController
子视图控制器,它有包含UITextField
的单元格,其文本内容是可编辑的。 The issue I'm running into is that when the user taps on a cell's UITextField
, the inputAccessoryView
's UITextView
refuses to resign first responder status, which prevents the content in the UITableViewCell
from being edited.我遇到的问题是,当用户点击单元格的UITextField
, inputAccessoryView
的UITextView
拒绝inputAccessoryView
第一响应者状态,这会阻止UITableViewCell
的内容被编辑。 The following warning is logged in the console:控制台中记录了以下警告:
First responder warning: '<UITextView: 0x7fc041041c00;
frame = ...' rejected resignFirstResponder when being removed from hierarchy
I've tried calling resignFirstResponder
and endEditing
on the UIInputView
and UITextView
directly with no success.我试过直接在UIInputView
和UITextView
上调用resignFirstResponder
和endEditing
,但没有成功。 I don't want the ChatViewController
to resign first responder status as that would cause the inputAccessoryView
to disappear.我不希望ChatViewController
退出第一响应者状态,因为这会导致inputAccessoryView
消失。
Edit: I also receive the warning when dismissing the keyboard interactively (instead of tapping on the UITableViewCell
's UITextField
.编辑:我在以交互方式关闭键盘时也会收到警告(而不是点击UITableViewCell
的UITextField
。
Could you please check the following:能否请您检查以下内容:
UITextView
is removed from super view:如果UITextView
从超级视图中移除:UITextView
being removed from the view hierarchy ? UITextView
是否从视图层次结构中删除?resignFirstResponder
before removing it from the super view.如果是这样,您resignFirstResponder
在将其从超级视图中删除之前先resignFirstResponder
。UITextView
subclass is being used:如果正在使用UITextView
子类:UITextView
, if so have you implemented canResignFirstResponder
to return false
.您是否使用UITextView
的子类,如果是,您是否实现了canResignFirstResponder
以返回false
。true
instead.你可以尝试返回true
吗?My solution:我的解决方案:
still have warning message when press hide keyboard, but works well for me.按隐藏键盘时仍然有警告消息,但对我来说效果很好。
This warning is also shown when using the iOS message app and whatsApp.使用 iOS 消息应用程序和 WhatsApp 时也会显示此警告。 There is no known way to get rid of that.没有已知的方法可以摆脱它。 It has no negative impact, I believe we should just ignore it.它没有负面影响,我认为我们应该忽略它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.