diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 8bac8ad..4c4d34c 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -67,6 +67,7 @@ - (void)awakeFromNib - (BOOL)becomeFirstResponder { [self reloadData]; + [self inputTextFieldBecomeFirstResponder]; return YES; } @@ -114,6 +115,8 @@ - (void)collapse - (void)reloadData { + BOOL inputFieldShouldBecomeFirstResponder = self.inputTextField.isFirstResponder; + [self.collapsedLabel removeFromSuperview]; [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; self.scrollView.hidden = NO; @@ -132,10 +135,9 @@ - (void)reloadData [self.scrollView setContentSize:CGSizeMake(self.scrollView.contentSize.width, currentY + [self heightForToken])]; [self updateInputTextField]; - [self.inputTextField becomeFirstResponder]; - if ([self.delegate respondsToSelector:@selector(tokenFieldDidBeginEditing:)]) { - [self.delegate tokenFieldDidBeginEditing:self]; + if (inputFieldShouldBecomeFirstResponder) { + [self inputTextFieldBecomeFirstResponder]; } } @@ -254,6 +256,13 @@ - (void)layoutInvisibleTextField [self addSubview:self.invisibleTextField]; } +- (void)inputTextFieldBecomeFirstResponder +{ + [self.inputTextField becomeFirstResponder]; + if ([self.delegate respondsToSelector:@selector(tokenFieldDidBeginEditing:)]) { + [self.delegate tokenFieldDidBeginEditing:self]; + } +} - (UILabel *)toLabel { @@ -341,7 +350,7 @@ - (void)setCursorVisibility }]]; BOOL visible = [highlightedTokens count] == 0; if (visible) { - [self.inputTextField becomeFirstResponder]; + [self inputTextFieldBecomeFirstResponder]; } else { [self.invisibleTextField becomeFirstResponder]; } diff --git a/VENTokenFieldSample/ViewController.m b/VENTokenFieldSample/ViewController.m index d10b1c1..b50205d 100644 --- a/VENTokenFieldSample/ViewController.m +++ b/VENTokenFieldSample/ViewController.m @@ -24,6 +24,7 @@ - (void)viewDidLoad self.tokenField.dataSource = self; self.tokenField.placeholderText = NSLocalizedString(@"Enter names here", nil); [self.tokenField setColorScheme:[UIColor colorWithRed:61/255.0f green:149/255.0f blue:206/255.0f alpha:1.0f]]; + [self.tokenField becomeFirstResponder]; } - (IBAction)didTapCollapseButton:(id)sender