Control should switch automatically after the user is done entering the text in UITextField
In my app i have two textfields and i want the control from one text field to switch to second control as soon as the user is done entering the values in the first textfi开发者_Go百科eld automatically.
Does anybody has any idea on this?
Thanks,
I assume "done entering" means the user hits return, ... button on keyboard.
UITextField has delegate with UITextFieldDelegate protocol. And here's method ...
- (BOOL)textFieldShouldReturn:(UITextField *)textField
... you can implement it in this way ...
...
self.myFirstTextField.delegate = self;
self.mySecondTextField.delegate = self;
...
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if ( textField == self.myFirstTextField ) {
// User hits return key on keyboard when editing first textfield
[mySecondTextField becomeFirstResponder];
} else if ( textField == self.mySecondTextField ) {
// User hits return key on keyboard when editing second textfield
// This simply removes focus from the second textfield and hides keyboard
[mySecondTextField resignFirstResponder];
}
return YES;
}
If "done entering" is not return, ... button on keyboard, you can implement this delegate's method ...
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
... to check UITextField's text when user did type.
精彩评论