Reputation: 2610
I have implemented a TTPickerTextField in my application, I would like to limit the number of choice the user can do it.
Now, the TTPickerTextField has no limit. The user can select an unlimited number of fields.
Thank a lot. Sahid
Upvotes: 1
Views: 218
Reputation: 6006
TTPickerTextField is a subclass of UITextField, so you should be able to use its delegate methods to do what you want. You can do this by implementing the textField:shouldChangeCharactersInRange
delegate method and returning NO
when the maximum number of tokens are reached.
Where you create and initialize the TTPickerTextField
, set the delegate method appropriately:
pickerTextField.delegate = self;
Then your delegate object (probably the controller) can implement the delegate method to limit the number of tokens:
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
BOOL canEdit = YES;
if (textField == pickerTextField) // 'pickerTextField' is the Three20's picker textfield that you want to limit.
{
if (range.length == 0 && pickerTextField.cells.count >= MAX_NUMBER_OF_TOKENS)
{
canEdit = NO;
}
}
return canEdit;
}
Upvotes: 1