判断文字输入或删除,删除@某人时整体删除,删除其他文字正常删除

<span style="font-family: Arial, Helvetica, sans-serif;">#pragma mark - UITextView delegate</span>
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@""]) {
        //删除
        if ((range.location <= (self.totalLength - 1)) && (range.location != 0) && (self.targetIDArray.count != 0)) {
            NSMutableString * MText = [NSMutableString stringWithString:textView.text];
            NSString * lastName = [self.targetNameArray lastObject];
            NSRange  lastNameRange = [MText rangeOfString:lastName];
            [MText deleteCharactersInRange:lastNameRange];
            textView.text = MText;
            self.totalLength -= lastNameRange.length;
            [self.targetNameArray removeLastObject];
            [self.targetIDArray removeLastObject];
            return NO;
        }
       
    }else
    {
        [self.sendButton setTitle:@"发送" forState:UIControlStateNormal];
    }
   
    return YES;
}

你可能感兴趣的:(ios,UITextView,文字删除,人名整体删除,判断输入是文字还是删除)