Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open the keyboard automatically on UITextField?

I have a very simple table and when tocuh a cell it opens a new view with one UITextfield. All I want is that the keyboard will automatically opens, without the user have to touch the UITextfield.

Its all done in Interface Builder, so I am not sure how I do this. I guess I need to set the focus at some point ?

Thanks

like image 261
eemceebee Avatar asked Feb 16 '10 14:02

eemceebee


People also ask

How do I add a keyboard to a uitextfield?

Click the UITextField UI component in the Main.storyboard file to select it. Then click View —> Inspectors —> Show Attributes Inspector menu item at Xcode top menu bar. Scroll down to the Text Input Traits section, there are three drop-down lists related to the keyboard.

How do I change the type of a uitextfield in Xcode?

How To Change UITextField Keyboard Type In Xcode Attribute Inspector. Click the UITextField UI component in the Main.storyboard file to select it. Then click View —> Inspectors —> Show Attributes Inspector menu item at Xcode top menu bar.

How to make the uitextfield’s keyboard resign the first responder?

This function will be called when you press the return key in the UITextField keyboard. So we can add the below code in the textFieldShouldReturn function to make the UITextField’s keyboard resign the first responder when pressing the return key. // This function is called when you click return key in the text field.

How do I format a string in uitextfield?

The UITextField class does not provide built-in support for formatting its string using an Formatter object, but you can use the text field’s delegate to format the content yourself. To do so, use the text field’s delegate methods to validate text and to format it appropriately.


2 Answers

To cause the keyboard to show up immediately you'll need to set the text field as the first responder using the following line:

[textField becomeFirstResponder]; 

You may want to place this in the viewDidAppear: method.

like image 179
jessecurry Avatar answered Sep 22 '22 21:09

jessecurry


Swift 3 & 4:

override func viewDidAppear(_ animated: Bool) {     super.viewDidAppear(animated)     textField.becomeFirstResponder() } 
like image 24
Nico S. Avatar answered Sep 22 '22 21:09

Nico S.