Skip to content

Commit

Permalink
Don't becomeFirstResponder on reloadData
Browse files Browse the repository at this point in the history
  • Loading branch information
ayanonagon committed Jul 18, 2014
1 parent 33f5886 commit bb4c9f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (void)awakeFromNib
- (BOOL)becomeFirstResponder
{
[self reloadData];
[self inputTextFieldBecomeFirstResponder];
return YES;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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];
}
}

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -341,7 +350,7 @@ - (void)setCursorVisibility
}]];
BOOL visible = [highlightedTokens count] == 0;
if (visible) {
[self.inputTextField becomeFirstResponder];
[self inputTextFieldBecomeFirstResponder];
} else {
[self.invisibleTextField becomeFirstResponder];
}
Expand Down
1 change: 1 addition & 0 deletions VENTokenFieldSample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bb4c9f3

Please sign in to comment.