Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField / UITextView: I need to be able to detect user "return" key, and I need to be able to do multiline... what can do both? [duplicate]

Possible Duplicate:
How to create a multiline UITextfield?

UITextField delegate will capture return key: - (BOOL)textFieldShouldReturn:(UITextField *)textField

but it won't do multiline like UITextView can. But UITextView, can it capture return key?

I need to capture key events: (return) and do multiline: "\n".... What can I do? thx

like image 781
jdl Avatar asked May 02 '12 23:05

jdl


1 Answers

A quick google search for "UITextView detect return" came up with this thread:

UITextView (editing) - detecting that next line event occured

(for convenience sake, I've posted the code below)

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
{
    if ( [text isEqualToString:@"\n"] ) {
        //Do whatever you want
    }
    return YES;
}
like image 163
orangething Avatar answered Nov 15 '22 10:11

orangething