I have a UITextfield
in which I want user to enter comma separated text
example : elephant,fox, etc, Also I want to restrict the user to enter at maximum 7 comma separated words.
I have written this code in the delegate method of UITextfield
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSArray *numberOfWords = [self.tagsTextField.text componentsSeparatedByString:@","];
if([numberOfWords count] > 6)
{
return NO;
}
else
{
return YES;
}
}
I am unable to achieve the desired behaviour please help!