I want to remove the linefeed that was entered in by the return key. But when I do the following it remove the last character from the text. Why?
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
{
NSLog(@"%d %d %@ %@",range.location,range.length, text, [textView text]);
if ( [text isEqualToString:@"\n"] ) {
NSString *s = [textView text];
s = [s substringToIndex:[s length] - 1]; // <------------
[tvText setText:[NSString stringWithFormat:@"%@\n>>",s]];
}
return YES;
}
I want the result to look like:
>>name
>>yoda
>> <---- cursor is moved to the right of ">>"
I think you can do something like this,