Setting a UITextField into editing mode programmatically

后端 未结 3 1983
囚心锁ツ
囚心锁ツ 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:39

    You have to call [textField becomeFirstResponder];

    0 讨论(0)
  • 2021-02-06 22:41

    Call becomeFirstResponder on the UITextField.

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

    0 讨论(0)
  • 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).

    0 讨论(0)
提交回复
热议问题