- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if([text isEqualToString:@"\n"])
{
[textquestionendEditing:YES];
if(textquestion.text.length == 0)
[selfSetPlaceholder];
returnNO;
}
if([text length]==0)
{
NSLog(@"yulang");
NSRange range=[textquestion.textrangeOfString:@"@"options:NSBackwardsSearch];
NSLog(@" location=%d,length=%d",range.location,range.length);
NSString *str=[textquestion.textsubstringFromIndex:range.location];
NSString *str1=[textquestion.textsubstringToIndex:range.location-1];
if([str isEqual:@"@yu"])
textquestion.text=str1;
}
returnYES;
}
原文:http://www.cnblogs.com/yulang314/p/3677490.html