From 1076a28d327fe5b4f7625f2fa8de6d04f99577fb Mon Sep 17 00:00:00 2001 From: Phillip Kast Date: Tue, 12 Mar 2013 13:34:10 -0700 Subject: [PATCH] fix a crash - textField:shouldChangeCharactersInRange:replacementString: must check if the delegate implements tokenField:shouldRemoveToken:representedObject: before calling it - if the method isn't implemented, the default should be to assume tokens can be deleted. --- JSTokenField/JSTokenField.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/JSTokenField/JSTokenField.m b/JSTokenField/JSTokenField.m index 94c6cf4..a8a98f5 100644 --- a/JSTokenField/JSTokenField.m +++ b/JSTokenField/JSTokenField.m @@ -373,10 +373,17 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang } NSString *name = [token titleForState:UIControlStateNormal]; + // If we don't allow deleting the token, don't even bother letting it highlight - if ([self.delegate tokenField:self shouldRemoveToken:name representedObject:token.representedObject]) { + BOOL shouldHighlight = YES; + if ([self.delegate respondsToSelector:@selector(tokenField:shouldRemoveToken:representedObject:)]) { + shouldHighlight = [self.delegate tokenField:self shouldRemoveToken:name representedObject:token.representedObject]; + } + + if (shouldHighlight) { [token becomeFirstResponder]; } + return NO; }