UITextField becomeFirstResponder works only once

社会主义新天地 提交于 2019-12-24 08:01:13

问题


In my app, there is the ability for the user to input their name.

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.

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


回答1:


If you have a property set for that UITextField, make sure to set it to nil after removing it from the view.




回答2:


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.



来源:https://stackoverflow.com/questions/9711929/uitextfield-becomefirstresponder-works-only-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!