Bird
0
0

You want to dismiss the keyboard when the user presses the Return key on UITextField. Which delegate method should you implement?

hard📝 Application Q9 of 15
iOS Swift - User Input and Forms
You want to dismiss the keyboard when the user presses the Return key on UITextField. Which delegate method should you implement?
AtextFieldDidBeginEditing(_:)
BtextFieldShouldEndEditing(_:)
CtextFieldShouldReturn(_:)
DtextFieldDidChangeSelection(_:)
Step-by-Step Solution
Solution:
  1. Step 1: Identify UITextFieldDelegate methods related to Return key

    textFieldShouldReturn(_:) is called when Return key is pressed.
  2. Step 2: Use this method to dismiss keyboard

    Inside textFieldShouldReturn(_:), call resignFirstResponder() to hide keyboard.
  3. Final Answer:

    textFieldShouldReturn(_:) -> Option C
  4. Quick Check:

    Dismiss keyboard on Return key = textFieldShouldReturn [OK]
Quick Trick: Use textFieldShouldReturn to dismiss keyboard on Return [OK]
Common Mistakes:
  • Using didBeginEditing instead
  • Confusing endEditing with Return key
  • Implementing unrelated delegate methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes