How can I make the keyboard appearing when a view is displayed?
Asked
Active
Viewed 3,811 times
2
-
Try This **textfield.becomeFirstResponder()** – Kaushik Makwana Feb 27 '18 at 10:12
-
Possible duplicate of [Force keyboard to show up via button (iPhone sdk)](https://stackoverflow.com/questions/2750445/force-keyboard-to-show-up-via-button-iphone-sdk) – Jaydeep Vora Feb 27 '18 at 10:13
-
Hello, I've already tried this, but I want the keyboard automatically appears without tapping on the textfield. – Blisko Feb 27 '18 at 10:14
-
@Blisko Yes, you can add that line on viewDidLoad(), than it will appear automatically – Kaushik Makwana Feb 27 '18 at 10:17
-
1Possible duplicate of [How to open the view with the keyboard appearing when the view is loaded?](https://stackoverflow.com/questions/2651136/how-to-open-the-view-with-the-keyboard-appearing-when-the-view-is-loaded) – Nazir Feb 27 '18 at 10:18
3 Answers
6
Try this code in viewDidAppear or viewWillAppear
textfieldname.becomeFirstResponder()

Prajnaranjan Das
- 1,378
- 1
- 9
- 26
0
Update for SwiftUI 3
If you are using UIViewRepresentable, you can use .becomeFirstResponder()
there.

Elias Al Zaghrini
- 237
- 2
- 13
-2
Put below code in ViewDidLoad
textfieldname.becomeFirstResponder()

Cœur
- 37,241
- 25
- 195
- 267

Jignesh Radadiya
- 68
- 1
- 9
-
2Well, to strictly answer the question, it would be done on `viewWillAppear` instead. – Cœur Feb 27 '18 at 10:18
-
Yes, you can put my code on viewillappear() instead of viewdid load – Jignesh Radadiya Feb 27 '18 at 10:22
-
I've put it in the ViewDidLoad but the keyboard didn't appear automatically. I don't use a textfied, but a custom view. Is this linked? – Blisko Feb 27 '18 at 10:23
-
This code only work with the controls that allow editing of text or texting,like UITextField and UITextView – Jignesh Radadiya Feb 27 '18 at 10:26
-
@Blisko Can you tell us a little more about the custom view? Does it contain a text field that you are trying to type into? If so, you might want to do something such as `customView.textField.becomeFirstResponder()` – Hodson Feb 27 '18 at 11:53
-
Hi I ve managed to display the keyboard with becomeFirstResponder() in the custom view. – Blisko Feb 27 '18 at 11:59