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
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 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.
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.
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.
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.
Swift 3 & 4:
override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) textField.becomeFirstResponder() }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With