I have 2 textfields, for login id and password. When user taps on email id, they keyboard type is email and for password, its default. They done button of both the keyboards, dismisses the keyboard. WHat i am trying to do is, once user fills both the id and password, they DONE button should be changed to "LOGIN" and i can perform selector method on it to login.
Can this be doable?
Thanks
If you are using standard iOS keyboard, then the only available return key type is
typedef enum {
UIReturnKeyDefault, // “Return”
UIReturnKeyGo, // “Go”
UIReturnKeyGoogle, // “Google”.
UIReturnKeyJoin, // “Join”.
UIReturnKeyNext, // “Next”.
UIReturnKeyRoute, // “Route”.
UIReturnKeySearch, // “Search”.
UIReturnKeySend, // “Send”.
UIReturnKeyYahoo, // “Yahoo”.
UIReturnKeyDone, // “Done”
UIReturnKeyEmergencyCall, // "Emergency Call”.
} UIReturnKeyType;
To detect the keychange on the keyboards you can register for name:UITextFieldTextDidChangeNotification . Lets say your textfield are emailTextField and passwordTextField.
First you register the notification, the detect the text input
// emailTextField
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(check)
name:UITextFieldTextDidChangeNotification
object:emailTextField];
// passwordTextField
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(check)
name:UITextFieldTextDidChangeNotification
object:passwordTextField];
- (void)check {
if ([emailTextField.text length] > 0 && [passwordTextField.text length] > 0) {
// Set the return key here, e.g:
emailTextField.returnKeyType = UIReturnKeyGo;
passwordTextField.returnKeyType = UIReturnKeyGo;
}
else {
// Set the return key here, e.g:
emailTextField.returnKeyType = UIReturnKeyNext;
passwordTextField.returnKeyType = UIReturnKeyNext;
}
}
When the return key tapped, it'll call textfield delegate. You can do something like this:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
// You can perform selector here, probably after checking if both of the textfields already filled out. E.g:
if ([emailTextField.text length] > 0 && [passwordTextField.text length] > 0) {
[self performSelector:@selector(login)];
}
return YES;
}
UITextInputTraits
protocol defines following UIReturnKeyType
-
typedef enum {
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
} UIReturnKeyType;
For your specific purpose you need to have custom button, you can check following tutorial - http://mhasantanim.wordpress.com/tutorial/iphone/customize-done-button/
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