0

Question, I have a UITextView in one of my views, but when the user hits the Enter key, the keyboard is removed. 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?

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
Rob Bonner
  • 9,276
  • 8
  • 35
  • 55

2 Answers2

3

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:

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • Thanks, but I am wanting the opposite to happen. The return key is removing the keyboard, and I want it to put in a new line. – Rob Bonner Feb 04 '10 at 19:00
  • @Rob: but that's the default behavior! Can you show us some of your code? – kennytm Feb 05 '10 at 07:19
  • Kenny, you are correct, and in looking for the code I found where I was removing the keyboard. This returned the form to the default behavior. Thanks for the response, it did send me back into the code. – Rob Bonner Feb 05 '10 at 17:09
0
(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
  // end editing and thus hide keyboard
  [textView resignFirstResponder];
  return YES;
}
Tafkadasoh
  • 4,667
  • 4
  • 27
  • 31
ans
  • 41
  • 1