How do I dismiss a UITextView using the Done keyboard button? [duplicate]
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.
精彩评论