Dynamically change UIKeyboards return key

I have two UITextfield, the user enters his name in the first, and electronic - in the second. I would like to know how to change the UIKeyboards return key depending on whether the text field has a name entry or not.

For example, if the nametextfield is empty, I would like the UIkeyboard return key to be next. else, if there is an entry in the nametextfield field, then when the user selects the email text field, I would like the return key to be sent.

Is it possible? if so, how can I do this? Any help would be appreciated.

+6
source share
4 answers

You may have a return key configured for prefix values, which you can see in the UIReturnKeyType enum for each UITextField .

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

Not sure if this is what you are looking for.

+6
source

You have the opportunity to customize the characteristics of the keyboard in the UITextFieldDelegate Protocol textFieldShouldBeginEditing: method , which is called before the text field becomes the first responder (indeed, to decide, it can become the first responder). If you do not yet have a delegate for the text field in question, you will have to assign it and implement at least this method. Presumably, the same object that processes the text field may contain delegate methods. The following implementation sets the return key to "Search".

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

You will need to look at the contents of the text fields to decide which value to use.

+4
source

textfield.returnKeyType = UIReturnKeySearch;

+1
source

All Articles