开发者

UITextView not remove keyboard

开发者 https://www.devze.com 2022-12-19 03:55 出处:网络
Question, I have a UITextView in one of my views, but when the user hits the Enter key, the keyboard is remov开发者_JAVA技巧ed.I really want the Enter key to put in a \\n.This happens in several other

Question, I have a UITextView in one of my views, but when the user hits the Enter key, the keyboard is remov开发者_JAVA技巧ed. I really want the Enter key to put in a \n. This happens in several other places in my app.

Lots of posts to have the return remove the keyboard, but nothing how to keep it.

In the IB, I have the return key type set to Default. Any other settings I need to check into?


Neither UITextView nor UITextField won't remove the keyboard by default. For UITextView that's because the user may really want to enter a line-break. If you want to remove the keyboard you need to write code.

See:

  • How to dismiss keyboard for UITextView with return key?
  • How do you dismiss the keyboard when editing a UITextField


(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
  // end editing and thus hide keyboard
  [textView resignFirstResponder];
  return YES;
}
0

精彩评论

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