1

I want to hide the keyboard after typing the content into the UITextView but i can not do this by default like UITextField. Is there any way to hide the keyboard, Rightnow i put the button which can help me out.If any default way to hide it then please tell me.

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
Jignesh Fadadu
  • 409
  • 4
  • 17

2 Answers2

1
[textView resignFirstResponder];

Here is your detail answer

Community
  • 1
  • 1
Praveen-K
  • 3,401
  • 1
  • 23
  • 31
1

Use following code for hide the keyboard from text view when user enter "\n"(new line) means press "Done" or "return" button.

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

    if([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }

    return YES;
}

Example1 and Example2.

Community
  • 1
  • 1
Chetan Bhalara
  • 10,326
  • 6
  • 32
  • 51
  • This is not a good answer at all. The point of a UITextView is usually to support multiple lines of text. The above code closes the keyboard whenever the Return key is pressed, so how can one type multiple lines?? The resignFirstResponder is indeed the correct way to dismiss a keyboard, but why link it to the newline character? The above answer would be fine if the question was about UITextField. – PaulG Dec 13 '12 at 15:34