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

1

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

Hemolysis answered 31/1, 2011 at 6:6 Comment(0)
S
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.

Segarra answered 31/1, 2011 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.