Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamically change UIKeyboards return key

I have two UITextfield the user enters his name into the first and email into the second. I would like to know how to change the UIKeyboards return key depending if the name text field has an entry or not.

For instance if nametextfield is empty then I would like the UIkeyboard return key to be Next else if the nametextfield has an entry in it then when the user selects the email text field I would like the return key to be submit.

Is this possible? if so how would I go about accomplishing it? any help would be appreciated.

like image 713
HurkNburkS Avatar asked Feb 25 '13 20:02

HurkNburkS


3 Answers

You can have return key customized to prefixed values that you can see in UIReturnKeyType enum for each UITextField.

textFieldName.returnKeyType = UIReturnKeyNext;
textFieldEmail.returnKeyType = UIReturnKeyDefault;

Not sure if this is what you're looking for though.

like image 128
smisiewicz Avatar answered Nov 11 '22 09:11

smisiewicz


You have a chance to set up keyboard characteristics in the UITextFieldDelegate Protocol method textFieldShouldBeginEditing: which is called before the text field becomes the first responder (indeed to decide if it may become the first responder). If you don't already have a delegate for the text field(s) in question you would have to assign one and implement at least that method. Presumably the same object handling the text field could hold the delegate methods. The following implementation sets the return key to "Search".

- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField {
    NSLog(@"textFieldShouldBeginEditing");
    textField.returnKeyType = UIReturnKeySearch;
    return YES;
}

You'd have to look at the contents of your text fields to decide what value to use.

like image 4
Charlie Price Avatar answered Nov 11 '22 08:11

Charlie Price


Make use of the textField.returnKeyType property.

you can check out all the available options here http://developer.apple.com/library/ios/documentation/uikit/reference/UITextInputTraits_Protocol/Reference/UITextInputTraits.html#//apple_ref/doc/c_ref/UIReturnKeyType

like image 1
Nitin Alabur Avatar answered Nov 11 '22 08:11

Nitin Alabur