diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 83dcaff..33f91d7 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -551,11 +551,16 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { [self unhighlightAllTokens]; - if ([self.delimiters containsObject:string]) { - if ([self.delegate respondsToSelector:@selector(tokenField:didEnterText:)]) { - if ([textField.text length]) { - [self.delegate tokenField:self didEnterText:textField.text]; - return NO; + NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; + for (NSString *delimiter in self.delimiters) { + if (newString.length > delimiter.length && + [[newString substringFromIndex:newString.length - delimiter.length] isEqualToString:delimiter]) { + NSString *enteredString = [textField.text substringToIndex:newString.length - delimiter.length]; + if ([self.delegate respondsToSelector:@selector(tokenField:didEnterText:)]) { + if (enteredString.length) { + [self.delegate tokenField:self didEnterText:enteredString]; + return NO; + } } } } diff --git a/VENTokenFieldSample/ViewController.m b/VENTokenFieldSample/ViewController.m index 7f79901..5e9b216 100644 --- a/VENTokenFieldSample/ViewController.m +++ b/VENTokenFieldSample/ViewController.m @@ -25,7 +25,7 @@ - (void)viewDidLoad self.tokenField.placeholderText = NSLocalizedString(@"Enter names here", nil); self.tokenField.toLabelText = NSLocalizedString(@"Post to:", nil); [self.tokenField setColorScheme:[UIColor colorWithRed:61/255.0f green:149/255.0f blue:206/255.0f alpha:1.0f]]; - self.tokenField.delimiters = @[@",", @";"]; + self.tokenField.delimiters = @[@",", @";", @"--"]; [self.tokenField becomeFirstResponder]; }