There is view with 2 UITextField and login button. When user is in password textbox keyboard is shown with return key set as "Go". How i can set that return key to make action from Login button so user don't need to close keyboard and touch Login button?
Thanx in advance for reply.
keys on the lower right of the numeric keypad, while the return key is situated on the right edge of the main alphanumeric portion of the keyboard. On ISO and JIS keyboards, return is a stepped double-height key spanning the second and third rows, below ⌫ Backspace and above the right-hand ⇧ Shift .
Via Tap Gesture This is the quickest way to implement keyboard dismissal. Just set a Tap gesture on the main View and hook that gesture with a function which calls view. endEditing . Causes the view (or one of its embedded text fields) to resign the first responder status.
it's simple
youPasswordtextField.delegate = self ; // in viewDidLoad or any suitable place
in your controllers .h file conform to UITextFieldDelegate protocol
3.implement delegate method
- (BOOL)textFieldShouldReturn:(UITextField *)textField // this method get called when you tap "Go"
{
[self loginMethod];
return YES;
}
-(void) loginMethod
{
// implement login functionality and navigate user to next screen
}
You could use the TextField Delegate method as below:-
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if(self.passwordTextField isFirstResponder){
[self.passwordTextField resignFirstResponder]; //Resign the keyboard.
[self loginMethod]; //call your login method here.
}
//Below case when user tap return key when done with login info then we move focus from login textfield to password textfield so as not making user to do this and for ease of user.
else{
[self.loginTextField resignFirstResponder];
[self.passwordTextField becomeFirstResponder];
}
return YES;
}
Also, don't forgt to set delegate as below along with setting UITextFieldDelegate in yourClass.h
self.passwordTextField.delegate = self;
self.loginTextField.delegate = self;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With