Setting a UITextField into editing mode programmatically

后端 未结 3 1991
囚心锁ツ
囚心锁ツ 2021-02-06 22:07

I have a UITextField that I want to set into editing mode (keyboard on screen and cursor in text field box) programatically. I know that the user will be in editin

3条回答
  •  温柔的废话
    2021-02-06 22:51

    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).

提交回复
热议问题