Search code examples
iphoneobjective-ciosuitextfieldfirst-responder

iPhone: why does sending the message resignFirstResponder remove the keyboard?


This is a two part question:

1) Why do we need to make the UITextField first responder in the first place ? It will work even if it is not the first responder.

2) Why does the keyboard go away when we send the message resignFirstResponder ? Does the method also remove the keyboard as a side effect ? Why is there not a separate method in UITextView to instruct it to remove the keyboard ?


Solution

  • Why do you want the resignFirstResponder message not to remove the keyboard?

    1. The UITextField becomes active (the cursor blinks inside the text field and the keyboard appears), only when you send becomeFirstResponder message or you click inside the text field.

    2. The resignFirstResponder message makes the text field inactive (the cursor is removed from the text field). If the cursor is not in the text field then why do you even need the keyboard there? Where you will send those text typed in the keyboard? Thats why the keyboard disappears automatically when the text field resigns as first responder.

      resignFirstResponder is the method in UITextView to instruct it to remove the keyboard.