问题描述
在我的应用中,用户可以输入其姓名.
In my app, there is the ability for the user to input their name.
将UITextField添加到视图中,并调用beginFirstResponder.在textFieldShouldReturn方法中,将调用resignFirstResponder.然后在textFieldShouldEndEditing中,将UITextField从视图中删除.
A UITextField is added to the view and becomeFirstResponder is called.In the textFieldShouldReturn method, resignFirstResponder is called.Then in textFieldShouldEndEditing, the UITextField is removed from the view.
这一切都很好,但是问题在于,当用户再次尝试输入其名称时,会显示UITextField,但不会显示键盘.
This all works fine, but the problem is that when the user tries to input their name a second time, the UITextField shows but keyboard does not.
我尝试了很多事情,例如四处走动成为/辞职第一响应者或保留/不保留文本字段,但是我似乎无法使它正常工作.有任何想法吗?谢谢
I have tried lots of things, like moving around become/resign firstresponder or retaining/not retaining the textfield, but I just cant seem to get it to work.Any ideas?Thanks
推荐答案
尝试在textFieldDidEndEditing中完成工作,并且当您第二次点击文本字段时,控件应进入textFieldShouldBeginEditing中,尝试检查是否有断点,它确实可以否则,问题是您的文本字段没有分配任何内存,如果在此函数中进行分配,请将此文本字段设置为第一响应者.
try doing the work in textFieldDidEndEditing, and when you tap on text field second time, control should go in textFieldShouldBeginEditing, try checking that with break points, it it does not goes then problem is that your textfield does not have any memory allocated and if it goes in this function set this textfield as first responder.
这篇关于UITextField成为firstResponder只能工作一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!