Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I dismiss a UITextView using the Done keyboard button? [duplicate]

Tags:

Possible Duplicate:
How to dismiss keyboard for UITextView with return key?

I have a UITextView and have done the following:

text.returnKeyType = UIReturnKeyDone; 

so that I can dismiss the keyboard when I press on done, however when i click on Done all it does is to go into the next line. How can I change this behavior? Thanks for the help

like image 932
aherlambang Avatar asked Jan 31 '11 06:01

aherlambang


People also ask

Which method can be used to dismiss the system keyboard if a UITextField or Uitextview is currently being edited?

You can ask the system to dismiss the keyboard by calling the resignFirstResponder method of your text field. Usually, you dismiss the keyboard in response to specific interactions. For example, you might dismiss the keyboard when the user taps the keyboard's return key.

Which delegate function removes keyboard in UITextField?

If you have a UITextField and you want to hide the keyboard when the user is pressing the return key, use the textFieldShouldReturn function. Be sure you have set the textField. delegate = self in your viewDidLoad() function.


1 Answers

There’s no shouldReturn on UITextView, but you can implement UITextViewDelegate and watch for insertions:

- (BOOL) textView: (UITextView*) textView     shouldChangeTextInRange: (NSRange) range     replacementText: (NSString*) text {     if ([text isEqualToString:@"\n"]) {         [textView resignFirstResponder];         return NO;     }     return YES; } 

Edit: And yes, sorry, this is a dupe.

like image 157
zoul Avatar answered Nov 02 '22 04:11

zoul