Bird
0
0

Which Swift method is used to dismiss the keyboard when tapping outside a UITextField?

easy📝 Syntax Q12 of 15
iOS Swift - User Input and Forms
Which Swift method is used to dismiss the keyboard when tapping outside a UITextField?
AtextField.resignFirstResponder()
BtextField.becomeFirstResponder()
CtextField.showKeyboard()
DtextField.hideKeyboard()
Step-by-Step Solution
Solution:
  1. Step 1: Identify method to dismiss keyboard

    Calling resignFirstResponder() on a UITextField tells it to stop being active, hiding the keyboard.
  2. Step 2: Check other options

    becomeFirstResponder() shows keyboard; showKeyboard() and hideKeyboard() do not exist in UIKit.
  3. Final Answer:

    textField.resignFirstResponder() -> Option A
  4. Quick Check:

    Dismiss keyboard = resignFirstResponder() [OK]
Quick Trick: Use resignFirstResponder() to hide keyboard [OK]
Common Mistakes:
  • Using becomeFirstResponder() which shows keyboard
  • Trying non-existent methods like hideKeyboard()
  • Not calling any method to dismiss keyboard

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes