Hey guys I need some help here. I have a subclass of UITextView which used to work under iOS6. But in iOS7 it has some weird behaviors. I override the shouldChangeTextInRange method so I can handle some keyboard inputs. The following code shows this strange behavior. When you press 'a'(or you can replace 'a' with any other char you want), the cursor will jump backward to somewhere in the UITextView then come back where its supposed to be. In iOS6 it never shows something like this. In iOS7, it wont affect user's input but it really looks weird.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
NSMutableString *updatedText = [[NSMutableString alloc] initWithString:textView.text];
[updatedText insertString:text atIndex:range.location];
const char *pch = [text UTF8String];
switch (*pch) {
case 'a': // you can replace it with any other char.
textView.text = updatedText;
return NO;
break;
default:
return YES;
break;
}
}
I put this demo in a simple project if you wanna see. https://dl.dropboxusercontent.com/u/75922069/test-uitextview.zip