Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submitting login form entry when return key on keyboard is tapped

I am looking for write action for done button in default keyboard,

I just created a loginpage with username and password.

The user fill the textfields when keyboard appears.

I want to submit that username and password to the done button in keyboard, instead of adding another submit button in uiview.

What can I do?

like image 793
ICoder Avatar asked Apr 04 '11 15:04

ICoder


1 Answers

You have to implement UITextFieldDelegate in you controller and then you can add the - (BOOL)textFieldShouldReturn:(UITextField *)textField method

and you have to do something like this

- (BOOL)textFieldShouldReturn:(UITextField *)textField {

    if (textField == usernameField) {
        [passwordField becomeFirstResponder];
    } else if (textField == passwordField) {
        //HERE THE LOGIN CODE
        [textField resignFirstResponder];
    }
    return YES;
}

where usernameField and passwordField are two IBOutlet linked to the UITextField for username and password. This code checks that if you press the return key when you are writing in username field pass the writing control to password field, and if you are in the password field and you hit return it's time to call your login code. The [textField resignFirstResponder]; dismiss the keyboard.

like image 98
Luca Bernardi Avatar answered Sep 24 '22 00:09

Luca Bernardi