How to open keyboard automatically on UITextField?

I have a very simple table, and when the tocuh cell opens a new view with one UITextfield field. All I want is for the keyboard to open automatically, without having to touch the UIText field.

All of this is done in Interface Builder, so I'm not sure how to do it. Think I need to set focus at some point?

thank

+53
objective-c iphone interface uitextfield builder
Feb 16 2018-10-16
source share
3 answers

To cause the keyboard to appear immediately, you need to set the text field as the first responder using the following line:

[textField becomeFirstResponder]; 

You can put this in the viewDidAppear: method.

+133
Feb 16 2018-10-16
source share
— -

Swift 3 and 4:

 override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) textField.becomeFirstResponder() } 
+9
Oct. 24 '17 at 11:44 on
source share

I prefer to add the first responder to the main topic -

  override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) DispatchQueue.main.async { self.textField.becomeFirstResponder() } } 

This comes in handy when a view controller view is added as a subview.

0
Jul 28 '19 at 9:14
source share



All Articles