开发者

Setting a UITextField into editing mode programmatically

I have a UITextField that I want to set into editing mode (keyboard on screen and cursor in text field box) programatically. I know开发者_如何学Python that the user will be in editing mode when this view appears onscreen, so I want to save the user from having to tap the text field.

The "editing" property of a UITextField is read only - so that doesn't work. Is there a way to set the UITextField into editing mode, with a keyboard onscreen, programmatically?


Call becomeFirstResponder on the UITextField.

Related question: How do I show the keyboard by default in UITextView?


You have to call [textField becomeFirstResponder];


Indeed call [textField becomeFirstResponder] in Obj-C or textField.becomeFirstResponder() in Swift.

However, make sure you call this in the viewDidAppear and not in the viewDidLoad to prevent strange behaviour (see: When set UITextField as FirstResponder programmatically, cause some weird actions on text editing).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜