How to hide keyboard in Swift when pressing Return in UITextField?
Hello, colleagues! I'm a beginner iOS developer in Swift and I've encountered what seems like a simple but very annoying problem. I'm creating a simple login form with a UITextField for entering a username. Everything works except one thing: when the user finishes typing and presses the "Return" (or "Done") key on the keyboard, the keyboard doesn't hide. It just stays on the screen, covering half of the interface.
I've already tried several approaches from the internet, but they didn't work. Here's my current code in ViewController:
```swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var nameTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Trying to set the delegate
nameTextField.delegate = self
}
No answers yet.
Log in to leave an answer