原因:中文九宫格输入值为特殊字符
@”➋➌➍➎➏➐➑➒”
所以在做输入校验的时候需要增加以上特殊字符的校验
实现:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
//获取高亮部分,在
//UITextRange *selectedRange = [textView markedTextRange];
//NSString * newText = [textView textInRange:selectedRange];
NSString *other = @"➋➌➍➎➏➐➑➒abcdefghijklmnopqrstuvwxyz1234567890";
if([other rangeOfString:text].location != NSNotFound){
return YES;
}
//中文字符集
NSString *regex = @"[\u4e00-\u9fa5]+";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
if ([pred evaluateWithObject:text] || [text isEqualToString:@""]) {
NSLog(@"输入的是中文字符和回退符号");
return YES;
}
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
NSLog(@"输入的不是中文,禁止输入");
return NO;
}