views:

147

answers:

2

When a user presses the "SEND"(return) button I want the keyboard to retract and do other stuff like send a message. But it only works SOMETIMES...

Why does this code only work SOMETIMES? I need it to work all the time obviously, but it doesn't.

- (void)textViewDidChange:(UITextView *)inTextView {

    NSString *text = myTextView.text;

    if ([text length] > 0 && [text characterAtIndex:[text length] -1] == '\n') {
        myTextView.text = [text substringToIndex:[text length] -1];
        [myTextView resignFirstResponder];
        [self sendMessage];

    }
}
+1  A: 

It only gets called if

([text length] > 0 && [text characterAtIndex:[text length] -1] == '\n')

is true. Is this always the case? Maybe add an NSLog statement outside and inside the state to see if it is indeed true all of the time.

Jordan
assuming myTextView is the text area that has the current focus.
Jordan
A: 

Checking for \n looks bizarre. Why would you do that?

Jaanus