When you initialize the alert view:
[[alertView textFieldAtIndex:0] setDelegate:self];
Now, self
here is your view controller. So you need to add <UITextFieldDelegate>
to its declaration.
Now implement the delegate method:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return (newLength > self.maxAlertTextFieldLength) ? NO : YES;
}
This is taken from this answer, linked answer in the comments.