开发者

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

This question already has answers here: Closed 10 years ago.

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜