First step is to set your controller (or other appropriate class) as the text field's delegate. You should conform that class to the UITextFieldDelegate protocol, and then do something like this:
myTextField.delegate = selfYou can also set the delegate in Interface Builder by control-dragging from the text field to File's Owner or some other object instance, and selecting the delegate outlet.
After that, you just need to implement a delegate method to limit the input.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
You can replace "5" with whatever value, variable, or constant is appropriate for your situation. Whenever we return NO from this delegate method, the pending edit is cancelled.
No comments:
Post a Comment