Reputation: 63
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.
Upvotes: 6
Views: 7897
Reputation: 11462
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
}
Upvotes: 14
Reputation: 3207
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;
Upvotes: 3