Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView adding new line unintentionally?

I have a scroll view which contains a UITextField and a UITextView. The UITextField return key is "Next" and when this is pressed I call [myTextView becomeFirstResponder]; A random new line is inserted into my textview so I start on the second line. How do I avoid this?

Also important to note that this does not happen when I tap directly on the UITextView rather than tapping the next key.

Thanks in advance!

like image 642
Stephen Avatar asked Jan 12 '14 17:01

Stephen


1 Answers

One solution to solve this is when you implement the textFieldShouldReturn: delegate method, be sure to return NO, and not YES. By returning NO, the newline isn't passed on to the text field.

- (BOOL)textFieldShouldReturn:(UITextField *)textField {     // move to next field or whatever you need     [myTextView becomeFirstResponder];      return NO; } 
like image 139
rmaddy Avatar answered Oct 04 '22 05:10

rmaddy