例: 若是是這樣判斷:code
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ // 不讓輸入表情 if (![NSString stringValidateEmoji:symptomTextView.text]) { return NO; } } return YES; }
就會出現刪除鍵失靈的問題,換用以下方法可解決:string
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ // 不讓輸入表情 if ([textView isFirstResponder]) { if ([[[textView textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textView textInputMode] primaryLanguage]) { kDLOG(@"輸入的是表情,返回NO"); UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"不能輸入表情" delegate:self cancelButtonTitle:nil otherButtonTitles:@"肯定",nil]; [alertView show]; return NO; } } return YES; }