From 92864dc37fe4b26132a5f438cc556bf460888fee Mon Sep 17 00:00:00 2001 From: Hugo Doria Date: Sat, 12 Oct 2013 00:37:49 -0300 Subject: [PATCH 1/2] add a maxLength option to QEntryElement --- quickdialog/QEntryElement.h | 1 + quickdialog/QEntryTableViewCell.m | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/quickdialog/QEntryElement.h b/quickdialog/QEntryElement.h index d1fd20ec..8f33f038 100644 --- a/quickdialog/QEntryElement.h +++ b/quickdialog/QEntryElement.h @@ -33,6 +33,7 @@ @property (nonatomic, strong) NSString *placeholder; @property (nonatomic, strong) NSString *prefix; @property (nonatomic, strong) NSString *suffix; +@property (atomic, assign) int maxLength; @property (assign) BOOL hiddenToolbar; @property(nonatomic, unsafe_unretained) id delegate; diff --git a/quickdialog/QEntryTableViewCell.m b/quickdialog/QEntryTableViewCell.m index 9606e478..e1792ef9 100644 --- a/quickdialog/QEntryTableViewCell.m +++ b/quickdialog/QEntryTableViewCell.m @@ -197,6 +197,14 @@ - (void)textFieldDidEndEditing:(UITextField *)textField { } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { + + NSUInteger newLength = [textField.text length] + [string length] - range.length; + if (newLength > [textField.text length]) { + if (textField.text.length >= _entryElement.maxLength) { + return NO; + } + } + if(_entryElement && _entryElement.delegate && [_entryElement.delegate respondsToSelector:@selector(QEntryShouldChangeCharactersInRange:withString:forElement:andCell:)]){ return [_entryElement.delegate QEntryShouldChangeCharactersInRange:range withString:string forElement:_entryElement andCell:self]; } From 6e55a70e0e45c4187fb6ed632a94868441b5d7df Mon Sep 17 00:00:00 2001 From: Hugo Doria Date: Sat, 12 Oct 2013 00:48:47 -0300 Subject: [PATCH 2/2] maxLength begins with 0 (not used) --- quickdialog/QEntryElement.m | 1 + quickdialog/QEntryTableViewCell.m | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/quickdialog/QEntryElement.m b/quickdialog/QEntryElement.m index 55048dfd..94fafbba 100644 --- a/quickdialog/QEntryElement.m +++ b/quickdialog/QEntryElement.m @@ -38,6 +38,7 @@ - (QEntryElement *)init { self.returnKeyType = UIReturnKeyDefault; self.enablesReturnKeyAutomatically = NO; self.secureTextEntry = NO; + self.maxLength = 0; } return self; } diff --git a/quickdialog/QEntryTableViewCell.m b/quickdialog/QEntryTableViewCell.m index e1792ef9..b12b1a06 100644 --- a/quickdialog/QEntryTableViewCell.m +++ b/quickdialog/QEntryTableViewCell.m @@ -200,7 +200,7 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang NSUInteger newLength = [textField.text length] + [string length] - range.length; if (newLength > [textField.text length]) { - if (textField.text.length >= _entryElement.maxLength) { + if (0 != _entryElement.maxLength && textField.text.length >= _entryElement.maxLength) { return NO; } }