iPhone: how can I activate a text field programmatically (and not wait for the user to touch it)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 03:53:00

问题


I have a UIViewController that is a UITextFieldDelegate, and I would like the keyboard for its text field to appear as soon as the user navigates to this view, without having to actually touch the text field. It would also be nice to be able to "dismiss" the entire view when the keyboard is dismissed. I am loading the view from a xib file.

I don't have an ivar in the code for the UITextField as yet. I would guess I need one. At this point I am just relying on the delegate to pop up the keyboard.

(I know its not a UITextViewDelegate, like the tag says, but I am new to stackoverflow and can't create the correct UITextFieldDelegate tag.)


回答1:


Sounds like you want to use [textField becomeFirstResponder] in viewDidAppear.



来源:https://stackoverflow.com/questions/3073072/iphone-how-can-i-activate-a-text-field-programmatically-and-not-wait-for-the-u

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