inputAccessoryView 中的 UITextField 不会成为FirstResponder [英] UITextField in inputAccessoryView won't becomeFirstResponder

查看:25
本文介绍了inputAccessoryView 中的 UITextField 不会成为FirstResponder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 songInfoView 的视图,其中包含 3 个 UITextFields 和一个 UIButton.我在父视图中创建了一个临时 UITextField 来调出键盘并将 SongInfoView 指定为 inputAccessoryView.这按预期工作.

I have a view called songInfoView with 3 UITextFields and a UIButton. I create a temp UITextField in the parent view to bring up the keyboard and assign songInfoView as the inputAccessoryView. This works as expected.

然后,我尝试将 SongInfoView 中的文本字段设置为第一响应者.光标移动到此字段,但当我尝试键入时,没有任何反应.我可以点击文本字段并按预期输入,但我希望它无需点击即可工作.我错过了什么吗?我这样做不正常吗?感谢您的帮助.

Then, I try to set a text field in songInfoView as first responder. The cursor moves to this field, but when I try to type, nothing happens. I can tap on the text field and type as expected, but I want it to work without having to tap on it. Am I missing something? Am I doing this out of order? Thanks for your help.

songInfoView = [[SongInfoViewController alloc]init];
songInfoView.delegate = self;

UITextField *tempTextField = [[UITextField alloc]initWithFrame:CGRectMake(10.0f, 10.0f, 50.0f, 30.0f)];
[self.view addSubview:tempTextField];
[tempTextField setInputAccessoryView:songInfoView.view];
[tempTextField becomeFirstResponder];
[songInfoView.titleTextField becomeFirstResponder];

推荐答案

好吧,我自己想出来了.事实证明(我认为)屏幕键盘(连同它的附件视图)有它自己的窗口.所以,在 songInfoView 的 viewDidAppear 方法中,我不得不调用

Well, I figured it out myself. It turns out (I think) that the on screen keyboard (along with it's accessory view) has it's own window. So, within songInfoView's viewDidAppear method, I had to call

[self.view.window makeKeyAndVisible];

请记住在键盘消失后用于加载键盘的视图控制器中再次调用它.希望这可以帮助其他人.

Just remember to call this again within the view controller you used to load the keyboard after the keyboard disappears. Hope this helps someone else down the road.

这篇关于inputAccessoryView 中的 UITextField 不会成为FirstResponder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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