Question

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 ?

Was it helpful?

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.

OTHER TIPS

you can send resignFirstResponder to TextView also but what actually you might wanted to ask is there is no delegate method for textview such as one exists for textfield i.e textFieldShouldReturn.
So answering your question, as textview is multiline ,pressing return takes the cursor to the next line. You need to explicitly place done button in separate view above the keyboard by pressing on it you can send resignFirstResponder message to textview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top