iPhone: how can I activate a text field programmat

2019-03-02 06:22发布

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条回答
Explosion°爆炸
2楼-- · 2019-03-02 07:06

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

查看更多
登录 后发表回答