24

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

Community
  • 1
  • 1
aherlambang
  • 14,290
  • 50
  • 150
  • 253

1 Answers1

56

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.

Community
  • 1
  • 1
zoul
  • 102,279
  • 44
  • 260
  • 354