Skip to content

Commit

Permalink
Merge pull request escoz#590 from hdoria/maxlength
Browse files Browse the repository at this point in the history
add a maxLength option to QEntryElement
  • Loading branch information
escoz committed Oct 14, 2013
2 parents 31ce96e + 6e55a70 commit e2befc1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions quickdialog/QEntryElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QuickDialogEntryElementDelegate> delegate;
Expand Down
1 change: 1 addition & 0 deletions quickdialog/QEntryElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ - (QEntryElement *)init {
self.returnKeyType = UIReturnKeyDefault;
self.enablesReturnKeyAutomatically = NO;
self.secureTextEntry = NO;
self.maxLength = 0;
}
return self;
}
Expand Down
8 changes: 8 additions & 0 deletions quickdialog/QEntryTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 (0 != _entryElement.maxLength && 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];
}
Expand Down

0 comments on commit e2befc1

Please sign in to comment.