我创建了一个 UITextView
,它允许在用户键入 @
时进行动态标记。
是否可以检测到 @
被删除,以停止我创建的特定标记过程?如果是这样,我该怎么做? UITextView
没有这样的委托(delegate)方法。
最佳答案
我会用
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
然后创建一个 NSString
,在其中存储添加到 UITextView
的最后一个字符。在上述方法中,添加以下代码段。
if ([text isEqualToString:@""] && [lastRecordedString isEqualToString@"@"]) {
//do whatever you want to do when an @ is deleted
}
lastRecordedString = [textView.text substringFromIndex:[string length]-1];
编辑:查看上面编辑过的代码。现在 lastRecordedString
是删除字符后 UITextView
中的最后一个字符。这应该有效。
关于iphone - UITextView 检测字符已删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12065690/