I have a textField in a SwiftUI file and want this fiel duo become the first responder and the keyboard should show up. In Swift I would simply do: textField.becomesFirstResponder(). Does anyone Has an idea how to do that in SwiftUI?
Asked
Active
Viewed 1,147 times
1
-
Possible duplicate: https://stackoverflow.com/questions/56507839/swiftui-how-to-make-textfield-become-first-responder – Pranav Kasetti Jun 08 '20 at 15:06
-
uups, thx, but very complicated... – Red Jun 08 '20 at 15:36
-
This can be done easily in iOS 15, take a look at **[this answer here](https://stackoverflow.com/a/59059359/5623035)** – Mojtaba Hosseini Jun 08 '21 at 17:55
1 Answers
0
for a simpler solution, instead of writing a custom textfield you can use this library, https://github.com/siteline/SwiftUI-Introspect:
TextField("placeholder", text: $someText).introspectTextField { textField in textField.becomeFirstResponder() }

BokuWaTaka
- 168
- 6