From 2c3bfa30a396deeaebb821cdbce8497c66ace8aa Mon Sep 17 00:00:00 2001 From: Malcolm Jarvis Date: Mon, 9 May 2016 14:00:11 -0700 Subject: [PATCH] Delegate for return key when not completing token When the user has the VENTokenField focused, and only has completed tokens, or no text at, tapping the return key now calls a new delegate method `tokenFieldDidReturn:`. This is useful for the user to confirm entry of tokens, allowing the app to move focus to another text field or view. `tokenField:didEnterText:` functionality has no change, and the code is written such that these two delegate methods are never called simultaneously. --- README.md | 3 ++- VENTokenField/VENTokenField.h | 1 + VENTokenField/VENTokenField.m | 8 ++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a27bb94..355a797 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,11 @@ Similar to ```UITableView```, ```VENTokenField``` provides two protocols: ``` diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index afcc026..dbcdf2b 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -548,10 +548,14 @@ - (NSString *)collapsedText - (BOOL)textFieldShouldReturn:(UITextField *)textField { - if ([self.delegate respondsToSelector:@selector(tokenField:didEnterText:)]) { - if ([textField.text length]) { + if ([textField.text length]) { + if ([self.delegate respondsToSelector:@selector(tokenField:didEnterText:)]) { [self.delegate tokenField:self didEnterText:textField.text]; } + } else { + if ([self.delegate respondsToSelector:@selector(tokenFieldDidReturn:)]) { + [self.delegate tokenFieldDidReturn:self]; + } } return NO;