Thursday, January 2, 2014

Limiting the maximum length of the input textField

Online has the following code to limit the maximum length of the input textField, the younger beginner, do not understand this sentence on. M file which is how
judgment which textField control- (BOOL) textField: (UITextField *) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString *) string
{
if (range.location> = 12)
return NO; / / return NO to not change text
return YES;
}
For example, I have a textField name tfPassword, shouldChangeCharactersInRange this method, there are no points to tfPassword
That how you can control tfPassword maximum input length, and it is up to what code to achieve the maximum limit textField input length of it?
Reply:
You have to realize UITextField delegate method, after the user input characters, the characters displayed on the screen before, it will call the delegate, you can determine the length here, prompting the user.
Reply:
I know, ah, but I was a novice, I did not know how to use ah brother, give a detailed code examples or the
Reply:
The first parameter is a pointer
uitextfieldThat is pass that judgment that the textfield come on.
Call this function, you can determine what textfield
Reply:
I want you to come up with the code to try it right! ? Empty say who will be the
Reply:
Assuming your file is UIAccountController.m

/ / Initialize
{
tfPassword.delegate = self;
}

- (BOOL) textField: (UITextField *) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString *) string
{
......
}


cited landlord fanhoucheng reply:
online following code to limit the maximum length of the input textField, brother beginner, do not understand this sentence on the m file inside. How to determine which textField control of
- (BOOL) textField: (UITextField *) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString *) string
{
if ......

No comments:

Post a Comment