Why do you need to create a new UITextField in the IBAction ?
You recreate a new UITextField which hides the existing one, hence you cannot enter anything).
The logical way to do it:
create the UITextField in the storyboard (I understand you did it)
connect to an IBOutlet that you name nameTextField
declare the placeholder in the storyboard (attributes inspector). It will be displayed automatically when the textField is empty.
do not create the IBAction yet
Then you should be able to type in nameTextField
If you need an IBAction (but do NOT create nameTextField subview inside)
declare in storyboard that the delegate of the textField is the UIViewController
declare that the UIViewController conforms to UITextFieldDelegate
change the IBAction (if you need to have some action once text entered) by:
@IBAction func insertName(_ sender: UITextField) {
let enteredName = sender.text
print("Entered Name:", enteredName ?? "")
}
What is the error message on line 13 ?
Topic:
UI Frameworks
SubTopic:
UIKit