During iOS development, we found that UITextView didn't want to use textFieldShouldReturn in UITextField: To hide the keyboard with the UITextView return key, we can determine whether the input character is a carriage return character.
First, declare that you want to implement the delegate of UITextView.
[Plain]
@ Interface MyViewController: UIViewController <UITextViewDelegate>
Then, set the delegate of textView.
TextView. delegate = self;
This attribute is usually set in viewDidLoad, or in nib (or storyboard.
Finally, implement the proxy method.
[Plain]
-(BOOL) textView :( UITextView *) textView shouldChangeTextInRange :( nsange) range replacementText :( NSString *) text
{
If ([text isEqualToString: @ "\ n"]) {
[TextView resignFirstResponder];
Return NO;
}
Return YES;
}
In this way, the UITextView return key in iOS is used to hide the keyboard.
From soloterry's column