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
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With